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

Screen GUI, Image Button not teaming and killing player, why?

So when you click a certain button on the GUI, it is meant to team you to a certain team.

Visible

while true do
	wait(10)
	script.Parent.Visible = true
end

RGH

local groupid = "1142229"
function Click(Player)
    if Player:IsInGroup(groupid) then
        Player.TeamColor = BrickColor.new("Institutional white")
		Player.Humanoid.Health = 0
    else 
end
end
script.Parent.MouseButton1Click:connect(Click)

PMC

local groupid = "2567972"
function Click(Player)
    if Player:IsInGroup(groupid) then
        Player.TeamColor = BrickColor.new("Lime green")
		Player.Humanoid.Health = 0
    else 
end
end
script.Parent.MouseButton1Click:connect(Click)

TRGH

local groupid = "2580112"
function Click(Player)
    if Player:IsInGroup(groupid) then
        Player.TeamColor = BrickColor.new("Navy blue")
		Player.Humanoid.Health = 0
    else 
end
end
script.Parent.MouseButton1Click:connect(Click)

SGH

local groupid = "2586305"
function Click(Player)
    if Player:IsInGroup(groupid) then
        Player.TeamColor = BrickColor.new("Earth green")
		Player.Humanoid.Health = 0
    else 
end
end
script.Parent.MouseButton1Click:connect(Click)

2 comments

0

you have an infinite while loop at the beginning. nothing after it happens, ever. it should go at the end.

0

^ Btw, they're different scripts

2 answers

✓ Accepted answer

You are trying to get Player from MouseButton1Click when the player is not passed by that function. Since these scripts are running on the client, you have access to game.Players.LocalPlayer, so local Player=game.Players.LocalPlayer should be written at the top.

Humanoid also is not a member of Player, it is a member of Player.Character.

local Player=game.Players.LocalPlayer
script.Parent.MouseButton1Click:connect(function()
	if Player:IsInGroup("1142229")then
		Player.TeamColor=BrickColor.new("Institutional white")
		Player.Character.Humanoid.Health=0
	end
end)

1 comment

0

No errors, but no functions either...

You keep putting Player as the parameter, but the MouseButton1Click event doesn't have any built-in parameters.

Therefore Player will always be nil.


The solution is super easy. LocalScripts (which these all should be - they're in GUIs, after all.) have access to the LocalPlayer property, so we can just use that to get the person clicking.

local Player = game.Players.LocalPlayer

---all your other stuff

1 comment

0

Still don't work

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