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

Why isn't this team changer delete'r working?

Asked by 5 years ago
local Player = script.Parent.Parent.Parent



if script.Parent.Parent.Name == "PlayerGui" then

    if Player.Team.TeamColor == BrickColor.new("Dark stone grey") then -- Checks if the team is a prisoner
        print("Prisoner")
        script.Parent:Destroy() -- removes it if your team is a prisoner
    end

    if Player.Team.TeamColor == BrickColor.new("White") then -- checks if your team is a civilian
        print("Civilian")
    end

end

How it works: it sees if you're a prisoner then deletes the GUI so you cant change and get unjailed and prints "Prisoner"

If you're a civilian then it just prints "civilian"...

0
Could you please accept my answer if I helped you? User#24403 69 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

It did work, though it only checked once. The if will not execute on its own each time.

Using the GetPropertyChangedSignal function we can listen for a specific property change.

local Player = game:GetService("Players").LocalPlayer

Player:GetPropertyChangedSignal("Team"):Connect(function()
    if Player.Team.TeamColor == BrickColor.new("Dark stone grey") then
        print("Prisoner")
        script.Parent:Destroy()
    elseif Player.Team.TeamColor == BrickColor.new("White") then
        print("Civilian")
    end
end)

Basically the code executes each time the team changes and only when the team changes. If you do not know about events already check them out here: events


Hopefully this answered your question and if it did, then don't forget to hit that "Accept Answer" button. It helps the both of us out :)
If you have any other questions then feel free to leave them down in the comments.
0
thanks fam troyw1987 7 — 5y
Ad

Answer this question