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

Player:LoadCharacter not working in RemoteEvent?

So I'm making a FPS game right now. I have two number values in a folder in Rep Storage representing the score values (number of kills) of the two teams. I also have it so that if a team has a score greater or equal to 30 it will fire a remote event to all clients giving the name of the winning team. That clients then show a GUI showing which team won the game. The clients then fire a remote event telling the player to LoadCharacter(). Unfortunately the player does not LoadCharacter() whenever I test it. Can anyone please help?

The regular script

while true do
	wait(1)
	if game:GetService("ReplicatedStorage"):WaitForChild("ScoreValues"):WaitForChild("RedScoreValue").Value >= 30 then
		game:GetService("ReplicatedStorage"):WaitForChild("EndGameEvent"):FireAllClients("Red")
		wait(10)
		game:GetService("ReplicatedStorage"):WaitForChild("ScoreValues"):WaitForChild("RedScoreValue").Value = 0
		game:GetService("ReplicatedStorage"):WaitForChild("ScoreValues"):WaitForChild("BlueScoreValue").Value = 0
	end
	if game:GetService("ReplicatedStorage"):WaitForChild("ScoreValues"):WaitForChild("BlueScoreValue").Value >= 30 then
		game:GetService("ReplicatedStorage"):WaitForChild("EndGameEvent"):FireAllClients("Blue")
		wait(10)
		game:GetService("ReplicatedStorage"):WaitForChild("ScoreValues"):WaitForChild("RedScoreValue").Value = 0
		game:GetService("ReplicatedStorage"):WaitForChild("ScoreValues"):WaitForChild("BlueScoreValue").Value = 0
	end
end

game:GetService("ReplicatedStorage"):WaitForChild("EndGameEvent").OnServerEvent:Connect(function(player)
	player:LoadCharacter()
end)

The local script

game:GetService("ReplicatedStorage"):WaitForChild("EndGameEvent").OnClientEvent:Connect(function(winner)
	script.Parent.Enabled = true
	script.Parent:WaitForChild("Win").Text = "Team "..winner.." won the game!"
	if winner == "Red" then
		script.Parent:WaitForChild("Win").BackgroundColor3 = Color3.new(255, 0, 0)
	elseif winner == "Blue" then
		script.Parent:WaitForChild("Win").BackgroundColor3 = Color3.new(0, 0, 255)
	end
	wait(10)
	script.Parent.Enabled = false
	game:GetService("ReplicatedStorage"):WaitForChild("EndGameEvent"):FireServer(game:GetService("Players").LocalPlayer)
end)

1 answer

✓ Accepted answer

I’ve encountered this problem before it’s because the while true do loop is constantly running while it’s never going to execute the code below

So I recommend putting this code in a separate script, I’m positive that will resolve the issue

game:GetService("ReplicatedStorage"):WaitForChild("EndGameEvent").OnServerEvent:Connect(function(player)
    player:LoadCharacter()
end)

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