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

Player:LoadCharacter not working in RemoteEvent?

Asked by 6 years ago
Edited 6 years ago

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

01while true do
02    wait(1)
03    if game:GetService("ReplicatedStorage"):WaitForChild("ScoreValues"):WaitForChild("RedScoreValue").Value >= 30 then
04        game:GetService("ReplicatedStorage"):WaitForChild("EndGameEvent"):FireAllClients("Red")
05        wait(10)
06        game:GetService("ReplicatedStorage"):WaitForChild("ScoreValues"):WaitForChild("RedScoreValue").Value = 0
07        game:GetService("ReplicatedStorage"):WaitForChild("ScoreValues"):WaitForChild("BlueScoreValue").Value = 0
08    end
09    if game:GetService("ReplicatedStorage"):WaitForChild("ScoreValues"):WaitForChild("BlueScoreValue").Value >= 30 then
10        game:GetService("ReplicatedStorage"):WaitForChild("EndGameEvent"):FireAllClients("Blue")
11        wait(10)
12        game:GetService("ReplicatedStorage"):WaitForChild("ScoreValues"):WaitForChild("RedScoreValue").Value = 0
13        game:GetService("ReplicatedStorage"):WaitForChild("ScoreValues"):WaitForChild("BlueScoreValue").Value = 0
14    end
15end
16 
17game:GetService("ReplicatedStorage"):WaitForChild("EndGameEvent").OnServerEvent:Connect(function(player)
18    player:LoadCharacter()
19end)

The local script

01game:GetService("ReplicatedStorage"):WaitForChild("EndGameEvent").OnClientEvent:Connect(function(winner)
02    script.Parent.Enabled = true
03    script.Parent:WaitForChild("Win").Text = "Team "..winner.." won the game!"
04    if winner == "Red" then
05        script.Parent:WaitForChild("Win").BackgroundColor3 = Color3.new(255, 0, 0)
06    elseif winner == "Blue" then
07        script.Parent:WaitForChild("Win").BackgroundColor3 = Color3.new(0, 0, 255)
08    end
09    wait(10)
10    script.Parent.Enabled = false
11    game:GetService("ReplicatedStorage"):WaitForChild("EndGameEvent"):FireServer(game:GetService("Players").LocalPlayer)
12end)

1 answer

Log in to vote
0
Answered by 6 years ago

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

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

Answer this question