In my game, when a player dies, a Gui will tween onto their screen. When they press the Okay button on the Gui, they will respawn. Now, how I scripted this is that I detected if the player pressed the Okay button buy using the OkayButton.MouseButton1Down:Connect(function()) function and sending a remote event to another server script. When the serverscript detects this remote event being sent, it triggers a function that does player:LoadCharacter(). For some reason, this all works except when the player presses the Okay Button, everyone in the server gets reset and teleports back to the spawn. Anybody know why?
LoadCharacter() is essentially respawning their character. Their character dies, then immediately spawns with a new character.
But is there a way to stop that event from respawning everybody in the server? I only want the player who pressed the Okay button to respawn.
Just call LoadCharacter() on only the player that hit the okay button.
probably something with the script. could we see it?
game:GetService('Players').PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
character:WaitForChild("Humanoid").Died:Connect(function()
game.ReplicatedStorage.Events.DiedEvent:FireClient(player)
end)
end)
game.ReplicatedStorage.Events.LoadCharacterEvent.OnServerEvent:Connect(function()
player:LoadCharacter()
wait()
game.ReplicatedStorage.Events.LoadCharacterEventFireback:FireClient(player)
end)
game.ReplicatedStorage.Events.LoadCharacterEventNo.OnServerEvent:Connect(function()
player:LoadCharacter()
end)
end)
Don’t worry about the Yes or No LoadCharacterEvents, just consider them as kind of an “Okay Button”. But basically, what this does is when a player dies, the serverscript sends a remote out to a local script that tweens a Gui onto the player’s screen. Then, when the player pressed the “Okay” button, the local script sends a remote back to the serverscript that then does the player:LoadCharacter() function.
try this. i think i found the issue
game:GetService('Players').PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
character:WaitForChild("Humanoid").Died:Connect(function()
game.ReplicatedStorage.Events.DiedEvent:FireClient(player)
end)
end)
game.ReplicatedStorage.Events.LoadCharacterEvent.OnServerEvent:Connect(function(PLR)
PLR:LoadCharacter()
wait()
game.ReplicatedStorage.Events.LoadCharacterEventFireback:FireClient(player)
end)
game.ReplicatedStorage.Events.LoadCharacterEventNo.OnServerEvent:Connect(function()
player:LoadCharacter()
end)
end)
You’re putting the event in a PlayerAdded event. This makes it so if one client fired the remote, it will fire several times for each player. Simply move the remote event connections outside of the player added event.
remote.OnServerEvent:Connect(function(player)
player:LoadCharacter() --fun fact, the very first parameter for onserverevent is the player that fired the remote
end)