Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Gui Button Script will not work?

Ive got the script in a localscript inside startergui. When i click it, it says "attempt to call a nil value" in the output. How would i get this to work?**

function onClick()
	if game.Players.LocalPlayer.Character.Head.Transparency == 1 then
		print("yes")
	else
		print("no")
	end

end
script.Parent.MouseButton1Click:connect()

2 answers

✓ Accepted answer

You forgot to pass the function "onClick" as a parameter to "connect"

Corrected:

function onClick()
    if game.Players.LocalPlayer.Character.Head.Transparency == 1 then
        print("yes")
    else
        print("no")
    end

end
script.Parent.MouseButton1Click:connect(onClick)

function onClick() if game.Players.LocalPlayer.Character.Head.Transparency == 1 then print("yes") else print("no") end

end script.Parent.MouseButton1Click:connect(onClick)

This discussion is preserved as it was. New answers, comments, and votes are closed.