Bug or code bad?

It will sound silly but I don’t know why it happens so I ask the community for help, I have this event that when a block called “Box” touches a part, it returns it to a specific coordinate, the problem happens when it touches the block again and it doesn’t send it, it just delete:

local debounce = false

script.Parent.DeathBox.Touched:Connect(function(hit)
	local player = game.Players:GetPlayerFromCharacter(hit.Parent)
	if player==nil then
		script.Parent.Box.CFrame = CFrame.new(Vector3.new(325.628, 70.447, 6.664)) * CFrame.Angles(0, -0, 0)
	end
end)

Why do you have to check if the player is nil? I think what you meant to do is do this check:

if player~=nil then
	script.Parent.Box.CFrame = CFrame.new(Vector3.new(325.628,70.447,6.664))*CFrame.Angles(0, -0, 0)
end
local debounce = false

script.Parent.DeathBox.Touched:Connect(function(hit)
	if debounce == false then
		debounce = true
		local player = game.Players:GetPlayerFromCharacter(hit.Parent)
		
		script.Parent.Box.CFrame = CFrame.new(Vector3.new(325.628, 70.447, 6.664)) * CFrame.Angles(0, -0, 0)
		
		wait(1)  -- Time to Start The Function agine
		debounce = false
	end
end) 

Because it is not a user, it is a block, a “Part”

you mean:

if hit.ClassName ~= "Player" then

end

?

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