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

Simple function failing to get past a 6 second wait?

Asked by 7 years ago

I'm trying to change the team of a player, wait a time, then change it back(when a button on a GUI is clicked), but after print-debugging, I've seen that it's not getting past the wait function - it kills the player, puts them into the "Dark stone grey" team, then stops. This is a little frustrating, as I see no reason this would happen. Thank you for all help. Script below:

local button = script.Parent

button.MouseButton1Down:connect(function()
    local pToKill = button.Parent.pNameBox.Text
    local p = game.Players:FindFirstChild(pToKill)
    local char = p.Character
    local pTeam = p.TeamColor
    print(pTeam)
    p.TeamColor = BrickColor.new("Dark stone grey")
    char.Humanoid.Health = 0
    wait(6)
    game.Players:FindFirstChild(pToKill).TeamColor = BrickColor.new(pTeam)
    char.Humanoid.Health = 0
    print(pTeam)


end)

1 answer

Log in to vote
2
Answered by
cabbler 1942 Moderation Voter
7 years ago
Edited 7 years ago

ScreenGuis normally completely reset when the player respawns. So, your script never completes after 6 seconds. To disable this, set your ScreenGui's "ResetOnSpawn" property to false.

0
I'm an idiot. Thank you. Brinceous 85 — 7y
Ad

Answer this question