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 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
How would I make this script for every player in the server when you click/buy the button? All help would be greatly appreciated
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.