I need suggestion/solve

Hello everyone , im trying to make worker system for eachplayer. Everything is cool but i need suggestions

game.ReplicatedStorage.Events.WorkingStatue.OnServerEvent:Connect(function(player,WorkingStatue,WorkerInfo)
while true do
if WorkingStatue == true then
wait(1)
workerHumanoid:MoveTo(game.workspace.Checkpoints.Dest.Position)
idleAnimationTrack:Stop()
runAnimationTrack:Play()
workerHumanoid.MoveToFinished:Wait()
runAnimationTrack:Stop()
while WorkerInfo[“Count”] < WorkerInfo[“Sieveable”] do
local ore = GetRandomOre()

			sieveAnimTrack:Play()
			WorkerInfo["Count"] = (WorkerInfo["Count"] + 1)
			wait(2)
			print(ore)
			sieveAnimTrack:Stop()
		end
		wait(1)
		runAnimationTrack:Play()
		workerHumanoid:MoveTo(game.workspace.Checkpoints.Dest2.Position)
		workerHumanoid.MoveToFinished:Wait()
		runAnimationTrack:Stop()
		WorkerInfo["Count"] = 0
	else
		wait(1)
		runAnimationTrack:Play()
		workerHumanoid:MoveTo(game.workspace.Checkpoints.Dest2.Position)
		workerHumanoid.MoveToFinished:Wait()
		runAnimationTrack:Stop()
		sieveAnimTrack:Stop()
		idleAnimationTrack:Play()
	end	
end

end)

this script is a worker stopper script
when you clicked gui worker needs to stop no matter what

firstable you need to click the gui for set WorkerStatue = false. when you clicked it it gets the info from client and send it to the server but when WorkerStatue = true and you set it false ,script dont break the WorkerStatue = true loop and it bugs. i need a way to break the loop

im new at forum sorry if something is wrong
thanks

Why not bring this into #help-and-feedback:code-review? That’d be a good place for it (Unless if of course, there’s an issue that needs ressolving)

Well, judging by how it looks, one issue I see is that you aren’t breaking your while true do loop anywhere in your script, which is basically resulting in it repeating over & over again (So say if you call 500 while true do loops, all of those will keep repeating at the same time without any of them stopping/breaking)

Since WorkingStatue I’m assuming is a Bool, you can’t really change it as you’re passing that specific variable from the client onto the server, and trying to click it again would make it fire again (Since it’s a function) So you might need to check when that specific value changes that’s replicated across both sides (Specifically in either ReplicatedStorage, or the workspace) So you can stop that said “Gui Worker”

1 Like