Hi everyone. I’m writing code to make races and whoever joins the race can win coins. That works alright, but when I try to transfer this information (the winner or if nobody wins) to a localscript to display on a ui, it doesn’t work. I will send small parts of both scripts as the entire script is kinda long and most of it is irrelevant.
ServerScript:
print(hit.Parent.Name.." has won! - SERVER")
game:GetService("ReplicatedStorage"):WaitForChild("ParkourWinFire"):FireAllClients(hit.Parent.Name)
-- when someone wins
print("NOBODY WON! - SERVER")
game:GetService("ReplicatedStorage"):WaitForChild("ParkourNobodyWon"):FireAllClients()
-- when nobody wins
I did some (quick) searching and most of the “FireAllClients not working” is solved because the server fired the event before the client could connect to the event. can you give some context about the firing of the remotes?
local playersPlaying = {}
local parkourroundtime = 20
local finish = game.Workspace.FinishPart
local someonehaswon = false
game:GetService("ReplicatedStorage"):WaitForChild("ParkourRaceJoinFire").OnServerEvent:Connect(function(player)
table.insert(playersPlaying, player)
print("There are/is currently "..#playersPlaying.." player(s) playing!")
game:GetService("ReplicatedStorage"):WaitForChild("ParkourRaceStartFire").OnServerEvent:Connect(function()
someonehaswon = false
for i,v in pairs(playersPlaying) do
v.Character:WaitForChild("HumanoidRootPart").CFrame = game.Workspace.ParkourRaceStartPart.CFrame
if v.Backpack:FindFirstChild("GravityCoil") then
v.Backpack.GravityCoil:Destroy()
end
end
finish.Touched:Connect(function(hit)
if someonehaswon == false then
if hit.Parent:FindFirstChild("Humanoid") then
print("This be a player")
print(hit.Parent.Name.." has won! - SERVER")
game:GetService("ReplicatedStorage"):WaitForChild("ParkourWinFire"):FireAllClients(hit.Parent.Name)
someonehaswon = true
for i,v in pairs(playersPlaying) do
v.Character:WaitForChild("Humanoid").Health = 0
end
task.wait(0.1)
for k in pairs(playersPlaying) do
playersPlaying[k] = nil
end
end
end
end)
wait(parkourroundtime)
if someonehaswon == false then
print("NOBODY WON! - SERVER")
game:GetService("ReplicatedStorage"):WaitForChild("ParkourNobodyWon"):FireAllClients()
for i,v in pairs(playersPlaying) do
v.Character:WaitForChild("Humanoid").Health = 0
end
for k in pairs(playersPlaying) do
playersPlaying[k] = nil
end
end
print("Should be nil:")
print(playersPlaying)
print("Round Ended!")
end)
end)