How should I fix this bug in my jump pad model

  1. What do you want to achieve? Keep it simple and clear!
    I want to fix a bug in my jump pad script

  2. What is the issue? Include screenshots / videos if possible!
    So my jump pad model is working fine until I found this bug. My jump pad can be destroy if player use a tool to hit it enough so when a player use the jump pad to increase their jump power, another player can destroy the jump pad and then the player that use the jump pad will keep the increase jump power and not return to normal because the script inside is also destroyed

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I tried thinking but still found no solution

here’s my jump pad script

local Value = script.Parent.Parent.Uses

local deb = false

script.Parent.Parent.Picture.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		if hit.Parent.Humanoid.JumpPower == 50 then
			if Value.Value > 0 and deb == false then
				deb = true
				
				hit.Parent.Humanoid.UseJumpPower = true
				hit.Parent.Humanoid.JumpPower = 80
				
				script.Parent.Boost:Play()
				
				local Parti = game.ReplicatedStorage.Particle.Green:Clone()
				Parti.Enabled = true
				Parti.Parent = hit.Parent.Torso
				Parti.Name = "PartiG"
				
				local Trail = game.ReplicatedStorage.Trails.Green:Clone()
				Trail.Parent = hit.Parent.Head

				local At0 = Instance.new("Attachment", hit.Parent.Head)
				At0.Name = "Attachment0"
				local At1 = Instance.new("Attachment", hit.Parent.Torso)
				At1.Name = "Attachment1"
				
				Trail.Attachment0 = At0
				Trail.Attachment1 = At1
				
				Value.Value = Value.Value - 1
				
				if Value.Value <= 0 then
					script.Parent.Parent.Neon.Color = Color3.fromRGB(80,80,80)
					script.Parent.Parent.Picture.Decal.Color3 = Color3.fromRGB(80,80,80)
				end

				wait(8)

				hit.Parent.Humanoid.JumpPower = 50
				local Ins0 = hit.Parent.Head.Attachment0
				local Ins1 = hit.Parent.Torso.Attachment1
				local InsTr = hit.Parent.Head.Green
				local InsPa = hit.Parent.Torso.PartiG
				Ins0:Destroy()
				Ins1:Destroy()
				InsTr:Destroy()
				InsPa:Destroy()
				
				if Value.Value <= 0 then
					script.Parent.Parent:Destroy()
				end
				
				deb = false
			end
		end
	end
end)

and here’s the breaking script

local Health = script.Parent.Break
local Bricks = script.Parent.Bricks

local S1 = script.Parent.Main.Hit
local S2 = script.Parent.Main.Hit2

Health.Changed:Connect(function()
	local TweenService = game:GetService("TweenService")

	local Info = TweenInfo.new(0.25, Enum.EasingStyle.Bounce, Enum.EasingDirection.InOut, 0, true, 0)
	local Goal = {Position = Vector3.new(script.Parent.Main.Position.X, script.Parent.Main.Position.Y + 1.5, script.Parent.Main.Position.Z)}

	local Tween = TweenService:Create(script.Parent.Main, Info, Goal)
	
	for i = 1,5 do
		local Part = Instance.new("Part")
		Part.CFrame = script.Parent.Main.CFrame
		Part.CanCollide = false
		Part.Anchored = false
		Part.Parent = script.Parent.Folder
		Part.AssemblyLinearVelocity = Vector3.new(math.random(-1,3)*math.random(10,11),50,math.random(-1,3)*math.random(10,11))
		Part.Size = Vector3.new(0.5,0.5,0.5)
		Part.Color = Color3.fromRGB(166,165,165)
		Part.CastShadow = false
	end
	
	Tween:Play()
	
	if Health.Value > 0 then
		S1:Play()
	end
	
	if Health.Value == 0 then
		S2:Play()
		wait(0.25)
		for i = 1, Bricks.Value do
			local Children = game.ReplicatedStorage.Bricks:GetChildren()
			local AmountOfChildren = #Children  
			local RandomPositionInArray = math.random(1, AmountOfChildren)
			local RandomChild = Children[RandomPositionInArray] 

			local Brick = RandomChild:Clone()
			local BrickMain = Brick:WaitForChild("Main")

			Brick:SetPrimaryPartCFrame(CFrame.new(script.Parent.Main.Position))
			Brick.Parent = game.Workspace.Bricks
			BrickMain.AssemblyLinearVelocity = Vector3.new(math.random(-1,3)*math.random(10,11),50,math.random(-1,3)*math.random(10,11))
		end
		script.Parent:Destroy()
	end
end)

try to use delay function.

local Part = script.Parent

Part.Touched:Connect(function(Hit)
local Humanoid = Hit.Parent:FindFirstChild(“Humanoid”)
if Humanoid then
Humanoid.JumpHeight = 100
wait(4)
Part:Destroy()

delay(5, function()
	Humanoid.JumpHeight = 7.2
		print("it works")
		
	end)
end

end)

local RS = game:GetService("ReplicatedStorage")
local Trails = RS:WaitForChild("Trails")
local Particle = RS:WaitForChild("Particle")

local Folder = script.Parent.Parent
local Value = Folder:WaitForChild("Uses")
local Neon = Folder:WaitForChild("Neon")
local Picture = Folder:WaitForChild("Picture")

local Part = script.Parent
local Boost = Part:WaitForChild("Boost")

local deb = false

Picture.Touched:Connect(function(Hit)
	if deb then
		return
	end
	if Hit.Parent:FindFirstChild("Humanoid") then
		local Humanoid = Hit.Parent:FindFirstChild("Humanoid")
		local Character = Hit.Parent
		local Head = Character.Head
		local Torso = Character:FindFirstChild("Torso") --THIS MEANS THAT THIS WILL ONLY WORK FOR R6 AVATARS
		if Humanoid.JumpPower == 50 and Torso then
			if Value.Value > 0 then
				deb = true
				Humanoid.UseJumpPower = true
				Humanoid.JumpPower = 80

				Boost:Play()

				local Parti = Particle.Green:Clone()
				Parti.Enabled = true
				Parti.Parent = Torso
				Parti.Name = "PartiG"

				local Trail = Trails.Green:Clone()
				Trail.Parent = Head

				local At0 = Instance.new("Attachment")
				At0.Parent = Head
				At0.Name = "Attachment0"
				local At1 = Instance.new("Attachment")
				At1.Parent = Torso
				At1.Name = "Attachment1"

				Trail.Attachment0 = At0
				Trail.Attachment1 = At1

				Value.Value -= 1

				if Value.Value <= 0 then
					Neon.Color = Color3.fromRGB(80,80,80)
					Picture.Decal.Color3 = Color3.fromRGB(80,80,80)
				end

				task.wait(8)
				
				if Humanoid then
					Humanoid.JumpPower = 50
				end
				
				if At0 and At1 and Parti and Trail then
					At0:Destroy()
					At1:Destroy()
					Parti:Destroy()
					Trail:Destroy()
				end
				
				if Value then
					if Value.Value <= 0 then
						Folder:Destroy()
					end
				end
			end
		end
	end
	task.wait(1)
	deb = false
end)

The debounce wasn’t being checked/set/unset correctly, also because “Torso” is referenced this script will only work for R6 avatars (I’ve added an if statement which checks if a part named “Torso” exists inside the touching player’s character model). This would’ve meant that if any R15 avatar triggered the Touched event resulting in the execution of the callback function connected to the event the script would have errored leading to its premature termination. I’ve also made some other minor optimisations to improve the script overall.

In addition to the above you were redeclaring variables for the instances which were created and parented to the various instances of the player’s character model whom which initially caused the Touched event to fire. This occurred after a 8 second yield which means that if the player’s character died in during that time and/or the player left the game the script would also error as you would be attempting to call :Destroy() on nil, so instead of this I’ve instead opted to use the old variables (no need to redeclare them) and check if they exist before calling the :Destroy() method through each one.

Also make sure this script isn’t a descendant of something which can be destroyed otherwise it will be destroyed also, potentially while it’s undergoing an execution cycle.