How would I make this script for all the players in a server?

Hello everyone, so I recently ran into a small problem with my auto jump/bunny hop system.
Like in tower of hell I want all the players to auto jump when someone buys the item.

Here is an example: https://gyazo.com/d3c75ecde54c5620406fad65393f7a33

Here is my button script: script.Parent.MouseButton1Click:Connect(function() game.ReplicatedStorage:WaitForChild("ShopEvents"):WaitForChild("BunnyHopFolder"):WaitForChild("BunnyHop"):FireServer() end)

Here is my ServerScriptService script: ``` game.ReplicatedStorage:WaitForChild(“ShopEvents”):WaitForChild(“BunnyHopFolder”):WaitForChild(“BunnyHop”).OnServerEvent:Connect(function(playerName)
if playerName.leaderstats.ParkourCoins.Value >= 500 then
playerName.leaderstats.ParkourCoins.Value = playerName.leaderstats.ParkourCoins.Value - 500

	for _,Player in pairs(game.Players:GetPlayers()) do
		local character = Player.Character or Player.CharacterAdded:Wait()
		local humanoid = character.Humanoid
		
		
		while true do
			wait()
			humanoid.Jump = true
		end
	end
end

end) ```

If you guys want a vid of the problem I could make one, all you have to do is ask :smiley:

How would I make this script for every player in the server when you click/buy the button? All help would be greatly appreciated :happy3:

1 Like

Wrap the “while true do” block in a coroutine or spawn() statement. It’s causing the outer loop to hang when it reaches the first player.

1 Like

ok I will try that thx :smiley:

Or better yet instead of spawning threads for each player you could just set some global ‘flag’ variable and spawn a single thread:

local BunnyHopEnabled = false

game.ReplicatedStorage:WaitForChild(“ShopEvents”):WaitForChild(“BunnyHopFolder”):WaitForChild(“BunnyHop”).OnServerEvent:Connect(function(playerName)
	if ((playerName.leaderstats.ParkourCoins.Value >= 500) and (not BunnyHopEnabled)) then
		playerName.leaderstats.ParkourCoins.Value = playerName.leaderstats.ParkourCoins.Value - 500
		BunnyHopEnabled = true
		local loop
		loop = game:GetService("RunService").Heartbeat:Connect(function()
			if (not BunnyHopEnabled) then
				loop:Disconnect()
			end
			for _, player in ipairs(game:GetService("Players"):GetPlayers()) do
				local humanoid = player.Character ~= nil and player.Character:FindFirstChild("Humanoid")
				if (humanoid) then
					humaoid.Jump = true
				end
			end
		end)
	end
end)

This way, when the round ends you would set ‘BunnyHopEnabled’ to false and that would cause the runservice event listener to disconnect.

1 Like

Thx I will try this right now, I will tell you if it worked :happy3:

I Have one problem I need to get the bool value because the timer script that resets the round is not in the same script, How would I change that?

Do I make it a value on the player or replicated storage? or maybe something else?

You could use a boolvalue object in serverscriptservice so that it can be changed from a different script.

alr, I am gonna try that right now btw thx for helping me dude.

Don’t use :WaitForChild() on server scripts. Everything is already loaded. This will take pointlessly longer execution times.

2 Likes

thx I never knew :WaitForchild’s() would take a longer time of execution.