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

[SOLVED] Why is my function only running one time? Function only runs one time after dying

Asked by 4 years ago
Edited 4 years ago

Hello guys. I have been trying to make a team selecter GUI for a game. I know there is something called resetonspawn , but its not very good in my situation. Everytime the script changes the team it does player:LoadCharacter() that way the player just keeps spawning with the gui. The script I have right now resets after the player dies, but only one time.

Here is my localscript:

local ResetGui = script.Parent.ResetGuiSpawn
local Gui = script.Parent.Parent

ImmigrantButton.MouseButton1Down:Connect(function(player)
    Gui.Enabled = false
    RE:FireServer(BrickColor.new(IT)) -- This doesn't matter.
    ResetGui:FireServer()
end)

And my script:

script.Parent.ResetGuiSpawn.OnServerEvent:Connect(function(Player)
    Player.CharacterAdded:Connect(function(Char)
        Char.Humanoid.Died:Connect(function()
            wait(5);
            Player.PlayerGui.ChangeTeamGui.Enabled = true;
        end)
    end)
end)

Any help would be much appreciated!

Edit: I found out a solution myself, but thanks for the answer.

1 answer

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

The function wont repeat because the script waits 5 seconds, and the player respawns on 5 seconds So it will reset every thing on the character , You can make simply changing the global script to

script.Parent.ResetGuiSpawn.OnServerEvent:Connect(function(Player)
       Player.CharacterAdded:wait()
local Char = Player.Character
       repeat wait() until Char == nil
wait(1)
Player.PlayerGui.ChangeTeam.Enabled = true
end)

If it dont work, Communicate me

0
Could you answer with the lua function? I don't understand the script dowsn't work now. peter21340 41 — 4y
0
The script completely stopped working. Idk what I did wrong. peter21340 41 — 4y
0
Done, I forgot the lua function lol shadow2008_br 176 — 4y
Ad

Answer this question