Help to fix problem

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)
2 Likes

I wish that when I get off the part, I don’t have auto-leveling, and when I get up on the part, I have

Cause im boutta go out of bed im gonna say this: Making script not run because HRP isnt hit part is a very very bad idea.

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.

Hope it helps!

You can show where to write in the script

Here you go hope this helps,

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)

11:23:49.181 Workspace.Part.Script:35: attempt to index nil with ‘GetPlayerFromCharacter’ - Server - Script:35
error

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)

Did you remove your ‘Players’ variable for the players service?

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.