Loop cant fire event?

Hello everyone, so I recently encountered this error in scripts. My loop/repeat loop or while true loop cant fire a remote event and I can’t figure out why?

Here is the script:

local minutesVal = game.ReplicatedStorage.TimerVal.minutesVal
local secondsVal = game.ReplicatedStorage.TimerVal.secondsVal

local bought = game.ReplicatedStorage.ShopEvents.LocalButtons.invisibilityButton

repeat
	wait()
	if minutesVal.Value == 0 and secondsVal.Value == 0 then
		print("GOT YA")
		bought.Value = false
		game.ReplicatedStorage.ShopEvents.ClaimedFolder.Claimed:FireServer()
	end
until bought.Value == true

Is this error due to the lack of wait time? or something else?

Maybe you need to put the bought variable in repeat until so it will se it everytime?

no, I am not talking about the bought value but the fire server event

for some weird reasons it doesn’t want to fire the event :confused:

You didnt understand me right It does The Function Everytime till the bought true But its false And it doesnt check everytime.

1 Like

I would create a variable that waits for the event and then just refer to that variable has the event. If I didn’t explain myself correctly, take this as an example:

local ShopEvents = game.ReplicatedStorage:WaitForChild("ShopEvents", 100)
local Remote = ShopEvents.ClaimedFolder:WaitForChild("Claimed", 100)

Remote:FireServer()
1 Like

Let me try both of your solutions, I will be right back.

The only thing I can think of is that the remote is getting over-used and is not working.

Firing remotes too fast can cause remote over-use.

1 Like

So should I do a while loop instead of a repeat?

No. It will work just like the repeat loop.

Try doing it so you only have to fire it once.
Anyways, I’ll have to go now. I might come back in a few hours and see if your problem has been solved, if it isn’t then I’ll try to help you.

1 Like

A while ago I made a script that fired a RemoteEvent every RunService.Heartbeat, which fires faster than while wait() do, so I don’t really think it would be a problem.

Doing that will lag the server.

It really depends on the task you’re trying to perform, my server-side script barely arrived to 1% of activity.

only my script isn’t server-sided, it’s a local script

Yeah I know, what I mean is that firing many times an event won’t lag the server if the server doesn’t have to perform a tough task.

if the bought value is set to true by default, and the minute or the secondval is not 0 then it will never fire that event, as it will just exit the loop.

game.ReplicatedStorage.ShopEvents.ClaimedFolder.Claimed.OnServerEvent:Connect(function()
 print("hello! it works.")
end)

this is the code i used to check it serversided and it worked with secondval and minuteval at 0, and bought at false.

1 Like

I will try that right away. thx for your response.

1 Like

I have one little problem I am using this for a timer, to check if its finished.

does it count down on the server or the client?