broken script

hey guys i have made a script but i cant seem to get it to work can anyone see any problems?



function GM:HUDPaint()
	local health = LocalPlayer():Health()
	local credit = LocalPlayer():GetNWInt("Credit")
	end
	self.BaseClass:HUDPaint()
end  

	local hx = 9
	local hy = ScrH() - (HUDHeight:GetInt() + 20)
	local hw = HUDwidth:GetInt()
	local hh = HUDHeight:GetInt()
	
	if LocalPlayer():GetActiveWeapon().IAmControlling then return end
	local backgroundcolor = Color(backgroundr:GetInt(), backgroundg:GetInt(), backgroundb:GetInt(), backgrounda:GetInt())
	local Healthbackgroundcolor = Color(Healthbackgroundr:GetInt(), Healthbackgroundg:GetInt(), Healthbackgroundb:GetInt(), Healthbackgrounda:GetInt())
	local Healthforegroundcolor = Color(Healthforegroundr:GetInt(), Healthforegroundg:GetInt(), Healthforegroundb:GetInt(), Healthforegrounda:GetInt())
	local HealthTextColor = Color( HealthTextr:GetInt(), HealthTextg:GetInt(), HealthTextb:GetInt(), HealthTexta:GetInt())
	draw.RoundedBox(6, hx - 8, hy - 90, hw + 30, hh + 110, backgroundcolor)

	draw.RoundedBox(6, hx - 4, hy - 4, hw + 8, hh + 8, Healthbackgroundcolor)

	if health ~= OldHealth then
		ChangeHealth(OldHealth, health)
		OldHealth = health
	end
	
	if ShowHealth > 0 then
		draw.RoundedBox(4, hx, hy, math.Clamp(hw * (ShowHealth / 100), 0, hw), hh, Healthforegroundcolor)
	end
	
	if oldcredit ~= credit then
		MakecreditShine()
		oldcredit = credit
	end
	
	draw.DrawText(math.Max(0, math.Round(ShowHealth)), "TargetID", hx + hw / 2, hy - 6, HealthTextColor, 1)
	draw.DrawText("
Wallet: " .. CUR .. credit .. "", "TargetID", hx, hy - 50, Color(255,255,255,creditChangeAlpha), 0)


	if LetterAlpha > -1 then
		if LetterY > ScrH() * .25 then
			LetterY = math.Clamp(LetterY - 300 * FrameTime(), ScrH() * .25, ScrH() / 2)
		end

		if LetterAlpha < 255 then
			LetterAlpha = math.Clamp(LetterAlpha + 400 * FrameTime(), 0, 255)
		end

		local font = ""

		if LetterType == 1 then
			font = "AckBarWriting"
		else
			font = "Default"
		end

		draw.RoundedBox(2, ScrW() * .2, LetterY, ScrW() * .8 - (ScrW() * .2), ScrH(), Color(255, 255, 255, math.Clamp(LetterAlpha, 0, 200)))
		draw.DrawText(LetterMsg, font, ScrW() * .25 + 20, LetterY + 80, Color(0, 0, 0, LetterAlpha), 0)
	end


You tell us the errors first?

the error is obvious. Lines 1-4.

@OP I’m going to spell it out to you - you need to learn lua before you try to code.

FIRST THING IS FIRST - To make a hud you make a seperate function, then add do it with hook.Add(“HUDPaint”, “Unique Name”, function) where function is the name of the function you created.

Come back to us if you’re still struggling.

done what you said still dont work and i dont get any errors.



function credit()
	local health = LocalPlayer():Health()
	local credit = LocalPlayer():GetNWInt("Credit")
	end
	self.BaseClass:HUDPaint() 

	local hx = 9
	local hy = ScrH() - (HUDHeight:GetInt() + 20)
	local hw = HUDwidth:GetInt()
	local hh = HUDHeight:GetInt()
	
	if LocalPlayer():GetActiveWeapon().IAmControlling then return end
	local backgroundcolor = Color(backgroundr:GetInt(), backgroundg:GetInt(), backgroundb:GetInt(), backgrounda:GetInt())
	local Healthbackgroundcolor = Color(Healthbackgroundr:GetInt(), Healthbackgroundg:GetInt(), Healthbackgroundb:GetInt(), Healthbackgrounda:GetInt())
	local Healthforegroundcolor = Color(Healthforegroundr:GetInt(), Healthforegroundg:GetInt(), Healthforegroundb:GetInt(), Healthforegrounda:GetInt())
	local HealthTextColor = Color( HealthTextr:GetInt(), HealthTextg:GetInt(), HealthTextb:GetInt(), HealthTexta:GetInt())
	draw.RoundedBox(6, hx - 8, hy - 90, hw + 30, hh + 110, backgroundcolor)

	draw.RoundedBox(6, hx - 4, hy - 4, hw + 8, hh + 8, Healthbackgroundcolor)

	if health ~= OldHealth then
		ChangeHealth(OldHealth, health)
		OldHealth = health
	end
	
	if ShowHealth > 0 then
		draw.RoundedBox(4, hx, hy, math.Clamp(hw * (ShowHealth / 100), 0, hw), hh, Healthforegroundcolor)
	end
	
	if oldcredit ~= credit then
		MakecreditShine()
		oldcredit = credit
	end
	
	draw.DrawText(math.Max(0, math.Round(ShowHealth)), "TargetID", hx + hw / 2, hy - 6, HealthTextColor, 1)
	draw.DrawText("
Wallet: " .. CUR .. credit .. "", "TargetID", hx, hy - 50, Color(255,255,255,creditChangeAlpha), 0)


	if LetterAlpha > -1 then
		if LetterY > ScrH() * .25 then
			LetterY = math.Clamp(LetterY - 300 * FrameTime(), ScrH() * .25, ScrH() / 2)
		end

		if LetterAlpha < 255 then
			LetterAlpha = math.Clamp(LetterAlpha + 400 * FrameTime(), 0, 255)
		end

		local font = ""

		if LetterType == 1 then
			font = "AckBarWriting"
		else
			font = "Default"
		end

		draw.RoundedBox(2, ScrW() * .2, LetterY, ScrW() * .8 - (ScrW() * .2), ScrH(), Color(255, 255, 255, math.Clamp(LetterAlpha, 0, 200)))
		draw.DrawText(LetterMsg, font, ScrW() * .25 + 20, LetterY + 80, Color(0, 0, 0, LetterAlpha), 0)
	end
	
hook.Add("HUDPaint", "paintthehud",credit)


You didn’t end the function.

You really, really need to learn syntax.

For starters you never even ended your function.

Did you even read the errors in your console?

i added a end and still didnt work

Then read the damned errors in your console, go to the line number it mentions, and debug it.

well i just found error once you add a end and is says

/gamemode/cl_init.lua:225: ‘<eof>’ expected near ‘end’

Please read and understand what that’s doing before you attempt anything else.

I think http://wiki.garrysmod.com/?title=Basic_Lua that is a more appropriate tutorial.

Look at part 3 where it tells you about Scope.

You clearly didn’t learn the basics and are just diving right in.

shrug That’s the page I learned lua from. I guess it’s different for me though. I have previous coding experience.

Yeah, I was the same, using another language first helps give you a foundation to build from.

Don’t think this guy has though.

its copyed and pasted off dark rp i cand do lua lol

First, copy/paste ISN’T coding lua. It’s copy/pasting. And that’s where you went wrong. Read the links we gave you, and you can start coding your own shit instead of copy/pasting everything.

ok i have made a new one but the problem is it works but first i want to remove suit armor and replace heath with credit i have a credit system i have



local credit = LocalPlayer():GetNWInt("credit")


now how do i make this replace heath?

Hide the health component of the HUD (http://wiki.garrysmod.com/?title=Gamemode.HUDShouldDraw) and draw a replacement box.

One way to do it would be to use draw.WordBox(): http://wiki.garrysmod.com/?title=Draw.WordBox

would it be
function paint()
draw.WordBox( 8, ScrW() / 2, ScrH() / 2, “Credit”…credit", “Default”, Color(50,50,75,100), Color(255,255,255,255) )
end
hook.Add( “HUDPaint”, “TestPaint”, paint )

or something?

You don’t need to hook it to HUDPaint if you’re making your own gamemode.

Also, why would you want the credits shown in the middle of the screen?

The quote after the second ‘credit’ will give you a syntax error.