I have this bit of code inside of a script parented to a part.
Basically, when the part is touched, I want it to clone. When it's done being touched, I want it to be deleted. I can't seem to get the touchEnded event to fire when the touch is actually over though. Its firing right when the player stands on it, instead of after the player is done touching it.
Any ideas?
OriginalPart = workspace:WaitForChild("redJoin")
redJoin = script.Parent --A part
Cloned = false --Debounce
--Touched
redJoin.Touched:Connect(function(Hit)
if Hit.Parent:FindFirstChild("Humanoid") and not Cloned then
Cloned = true
local newJoin = redJoin:Clone() --Clone
newJoin.Name = "redNewJoin"
newJoin.Position = script.Parent.Position + Vector3.new(4, 0, 0)
newJoin.Parent = workspace
end
end)
--Touch ended
redJoin.TouchEnded:Connect(function(Hit)
if Hit.Parent:FindFirstChild("Humanoid") and Cloned then
if script.Parent.Name == "redNewJoin" then
redJoin:Destroy() --If step off the part, destroy
end
end
end)
Appreciated :v:

2 comments
Touch ended is not always reliable. You shoul use raycast or region
Thanks for the feedback. I'll check it out sometime.