Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 8 years ago

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)
0
you have an infinite while loop at the beginning. nothing after it happens, ever. it should go at the end. 1waffle1 2908 — 8y
0
^ Btw, they're different scripts TheHospitalDev 1134 — 8y

2 answers

Log in to vote
2
Answered by
1waffle1 2908 Trusted Badge of Merit Moderation Voter Community Moderator
8 years ago

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)
0
No errors, but no functions either... TheHospitalDev 1134 — 8y
Ad
Log in to vote
1
Answered by
Perci1 4988 Trusted Moderation Voter Community Moderator
8 years ago

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
0
Still don't work TheHospitalDev 1134 — 8y

Answer this question