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

Anyone know why the script wont proceed after it displays the players name? [SOLVED]

Asked by 6 years ago
Edited 6 years ago

Anyone know why this script wont output the surface gui from the team color? it outputs the players name but wont continue

This is for a tool and if you click on someone it will give you their name and depending on what team they're in it will output a text box

the If function at line 35 is where the problem occurs, it also happens for the other functions

--client

local player = game.Players.LocalPlayer
local tool = script.Parent -- lets say this was the tool


tool.Equipped:Connect(function(mouse) 
    mouse.Button1Down:Connect(function()
        script.parent.Process:Play()
        script.Parent.Display.SurfaceGui.INFECTED.Visible = false
        script.Parent.Display.SurfaceGui.CLEAR.Visible = false
        script.Parent.Display.SurfaceGui.IMMUNE.Visible = false
        script.parent.Clear.Transparency = 1
        script.parent.Immune.Transparency = 1
        script.parent.Infected.Transparency = 1
        script.Parent.Processing.Transparency = 0
        wait(0.5)
        script.Parent.Processing.Transparency = 1
        wait(0.5)
        script.Parent.Processing.Transparency = 0
        wait(0.5)
        script.Parent.Processing.Transparency = 1
        wait(0.5)
        script.Parent.Processing.Transparency = 0
        wait(0.5)
        script.Parent.Processing.Transparency = 1
        wait(0.5)
        script.parent.Process:Stop()
        script.parent.Clear.Transparency = 1
        script.parent.Immune.Transparency = 1
        script.parent.Infected.Transparency = 1
        if mouse.Target then
            for _,v in pairs(game.Players:GetPlayers()) do -- literate through all the players
                script.Parent.Display.SurfaceGui.NAME.Text = v.Name 
                if v.TeamColor == ("Bright red") then
                    script.parent.Infected.Transparency = 0
                    script.Parent.Display.SurfaceGui.INFECTED.Visible = true
                    break
                end
                if v.TeamColor == ("Black") then
                    script.parent.Clear.Transparency = 0
                    script.Parent.Display.SurfaceGui.CLEAR.Visible = true
                    break
                end
                if v.TeamColor == ("White") then
                    script.parent.Clear.Transparency = 0
                    script.Parent.Display.SurfaceGui.CLEAR.Visible = true
                    break
                end
                if v.TeamColor == ("Navy blue") then
                    script.parent.Immune.Transparency = 0
                    script.Parent.Display.SurfaceGui.IMMUNE.Visible = true
                    break
                end
            end
        end
    end)
end)

1 answer

Log in to vote
1
Answered by 6 years ago

I'm on my computer instead of my phone now, so I may be able to fix this. First thing I'm going to do is make your script look less messy:

tool.Equipped:Connect(function(mouse) 
    mouse.Button1Down:Connect(function()
        if mouse.Target then
            for _,v in pairs(game.Players:GetPlayers()) do -- literate through all the players
                script.Parent.Display.SurfaceGui.NAME.Text = v.Name 
                if mouse.Target.Parent == v.Character then
                    if v.TeamColor == "Bright red" then
                        script.parent.Infected.Transparency = 0
                        script.Parent.Display.SurfaceGui.INFECTED.Visible = true
                        break
                    end
                end
            end
        end
    end)
end)

Now that its easier to read, we need to completely re-write it.

One thing I'm not understanding is why you felt the need to go through every player, when you already have their name (if the mouse.Target returns as a character body part. Lets take that out:

tool.Equipped:Connect(function(mouse) 
    mouse.Button1Down:Connect(function()
        if mouse.Target then
            script.Parent.Display.SurfaceGui.NAME.Text = v.Name 
            if mouse.Target.Parent == v.Character then
                if v.TeamColor == "Bright red" then
                    script.parent.Infected.Transparency = 0
                    script.Parent.Display.SurfaceGui.INFECTED.Visible = true
                    break
                end
            end
        end
    end)
end)

Clearly this script won't work on its own, so now we're going to find the player, without going through the whole list:

tool.Equipped:Connect(function(mouse) 
    mouse.Button1Down:Connect(function()
        if mouse.Target then
            if game.Players:FindFirstChild[mouse.Target.Parent.Name] then
                plr = game.Players[mouse.Target.Parent.Name]
                script.Parent.Display.SurfaceGui.Name.Text = plr
                if game.Players[plr].TeamColor == "Bright red" then
                    script.parent.Infected.Transparency = 0
                    script.Parent.Display.SurfaceGui.INFECTED.Visible = true
                    break
                end
            end
        end
    end)
end)

I'm going to be completely honest here: I have no idea if this fixed any errors, if it did it was all luck, I just wanted to make the code less sloppy.

0
Yeah tried this but it didn't work, I have posted the full script and that actually does work and gets the players name but still cannot find a way for the if function to make sure the players TeamColor is a certain color TheBlue_Hood -5 — 6y
Ad

Answer this question