I want this remotevent to fire only once(which I’ll get to eventually), but currently I’m interested in how come it fires exactly twice, and no more than that. I don’t understand why it’d fire twice for each player(I tested with another person) if the number of players is the cause , as it’s a serverscript.
P.S: forgot to add the screenshot of the client remoteevent printing “Hello” twice as well.
local presidenteTeam = game.Teams["El presidente"]
local civilian = game.Teams.Civilian
local Players = game:GetService("Players")
local votec = game.ReplicatedStorage:FindFirstChild("voteclient")
local sound = Instance.new("Sound", workspace)
while true do
wait(4)
if #presidenteTeam:GetPlayers() == 0 then
if #civilian:GetPlayers() > 1 then
print("election")
sound.SoundId = "rbxassetid://9071337529"
sound:Play()
votec:FireAllClients()
sound.Ended:Wait()
sound:Destroy()
end
end
end
You are using while true, which runs constantly nonstop. Also you are going to use FireAllClients when you are using an if statement for if there is more than one person in the server.
You have it wrapped in a while loop and waiting 4 seconds and this is the reason why its printing twice because if you look at the time stamp you can see the 4 second difference
I believe this is because you are destroying the sound in the first loop, leading to it printing “election” twice and erroring here
The while loop would stop because of this error. So to fix this, create the sound within the loop.
local presidenteTeam = game.Teams["El presidente"]
local civilian = game.Teams.Civilian
local Players = game:GetService("Players")
local votec = game.ReplicatedStorage:FindFirstChild("voteclient")
while true do
wait(4)
if #presidenteTeam:GetPlayers() == 0 then
if #civilian:GetPlayers() > 1 then
print("election")
local sound = Instance.new("Sound", workspace)
sound.SoundId = "rbxassetid://9071337529"
sound:Play()
votec:FireAllClients()
sound.Ended:Wait()
sound:Destroy()
end
end
end
The remote event wouldn’t be a problem here. That would only be a problem if you were firing it more than 10 times a second (this is a rough estimation, but it probably takes way more than that).