How do I loop this Check? The script is a ServerScript, and player is defined.
local playerGui = player:WaitForChild("PlayerGui")
local countdownVal = playerGui:WaitForChild("Emotes").Holder.countDown
countdownVal.Changed:Connect(function()
if countdownVal.Value == 0 then
emoteEvent:FireAllClients(player)
print("Fired event to "..player.Name)
end
end)
Is that entire script? cant really understand what you want to get.
Also, you putting player into FireAllClient which doesn`t take player as argument because its firing to all players
Somewhat. Basically I want to loop this check because I’m making a reward system. When the countdown reaches zero, it fires an event. I want it to repeat that process until the player leaves.
Well you could try this but just what HafuPlay said, It’s hard to understand what you want to achieve.
Maybe a clearer explanation would help?
local playerGui = player:WaitForChild("PlayerGui")
local countdownVal = playerGui:WaitForChild("Emotes").Holder.countDown
local function CheckCountdown()
while countdownVal.Value > 0 do
wait(1)
end
-- The countdown reached zero, trigger the reward system here or add more code
emoteEvent:FireAllClients(player)
print("Fired event to " .. player.Name)
end
spawn(CheckCountdown)
The countDown value counts down all the way to zero, and when this happens, it rewards a player. The countDown value repeats (in a separate script), and the check loops again to see if countDown has reached zero again.
local playerGui = player:WaitForChild("PlayerGui")
local countdownVal = playerGui:WaitForChild("Emotes").Holder.countDown
local given = false
spawn(function()
while wait() do
if countdownVal.Value == 0 and not given then
emoteEvent:FireAllClients(player)
print("Fired event to " .. player.Name)
given = true
elseif countdownVal.Value > 0 then
given = false
end
end
end)
No, just copying the code should work.
Reaction to your EDIT: Any errors or something like that? Are you sure the timer counts down to 0 at all?
Maybe add some debug prints like a print(countdownVal.Value)
I see the problem. The value of the countVal doesn’t update.
EDIT: Nevermind, got it working. The only problem is that the reward script you sent doesn’t print again after it reaches zero.
game.Players.PlayerAdded:Connect(function(player)
local playerGui = player:WaitForChild("PlayerGui")
local countdownVal = playerGui:WaitForChild("Emotes").Holder.countDown
local given = false
while task.wait() do
if countdownVal.Value == 0 and not given then
given = true
emoteEvent:FireClient(player)
print("Fired event to "..player.Name)
else
given = false
end
end
end)
It just spams the print for no reason.
EDIT: Fixed it, now for the actual reward itself.