Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

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

3 comments

0

Could you answer with the lua function? I don't understand the script dowsn't work now.

0

The script completely stopped working. Idk what I did wrong.

0

Done, I forgot the lua function lol

This discussion is preserved as it was. New answers, comments, and votes are closed.