Hello, I have a problem with the script, when I stand on the part, I start auto-pumping, but when I get off it, I still have auto-pumping, here is the script help to fix
local playersInside: {Player} = {}
script.Parent.Touched:Connect(function(hit)
if hit.Name ~= "HumanoidRootPart" then return end
local player = Players:GetPlayerFromCharacter(hit.Parent)
if not player then return end
local strength = player:FindFirstChild("Strength")
if not strength or strength.Value < 100 then return end
table.insert(playersInside, player)
while table.find(playersInside, player) do
task.wait(2)
if not table.find(playersInside, player) then return end
player:FindFirstChild("Endurance").Value += 1e90
end
end)
script.Parent.TouchEnded:Connect(function(hit)
if hit.Name ~= "HumanoidRootPart" then return end
local player = Players:GetPlayerFromCharacter(hit.Parent)
if not root or not player then return end
local playerIndex = table.find(playersInside, player)
if playerIndex then
table.remove(playersInside, playerIndex)
end
end)
You need to add a debounce, the way to do this is make a variable that is false (you can name this anything) and after your .Touched Event, say if not debounce then then set the debounce to true and later on in the script add a task.wait()
after your desired waiting time set the debounce to false so the script will active when called again.
local playersInside: {Player} = {}
local debounce = false -- change name if u want
local YourWaitTime = 5 -- change waitTime if u need
script.Parent.Touched:Connect(function(hit)
if not debounce then
debounce = true -- this makes the script not fire until debounce is false again
if hit.Name ~= "HumanoidRootPart" then return end
local player = Players:GetPlayerFromCharacter(hit.Parent)
if not player then return end
local strength = player:FindFirstChild("Strength")
if not strength or strength.Value < 100 then return end
table.insert(playersInside, player)
task.delay(YourWaitTime, function() -- task.delay is task.wait() but it wont disrupt the script
debounce = false
end)
while table.find(playersInside, player) do
task.wait(2)
if not table.find(playersInside, player) then return end
player:FindFirstChild("Endurance").Value += 1e90
end
end
end)
script.Parent.TouchEnded:Connect(function(hit)
if hit.Name ~= "HumanoidRootPart" then return end
local player = Players:GetPlayerFromCharacter(hit.Parent)
if not root or not player then return end
local playerIndex = table.find(playersInside, player)
if playerIndex then
table.remove(playersInside, playerIndex)
end
end)
im on my phone rn so I can’t rly code but this might solve it, Before saying :GetPlayerFromCharacter check if the player exists by
if player then
(your code here)