Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Touched event brick only works once?

This script is for a brick that clones the avatar who steps on it, to avoid crashes I used debounce and a 60 second wait, but the script will only work once and won't reset.

Anyone know what's causing the problem?

local debounce = false

game.Workspace.ClonedPart.Touched:Connect(function(hit)
	if not debounce then
		
		debounce = true
		script.Parent.BrickColor = BrickColor.new('Really red')
		local avatar = hit.Parent
		avatar.Archivable = true
		local clonedPerson = avatar:Clone()
		clonedPerson.Name = ('SellBot')
		clonedPerson.Parent = game.Workspace
		clonedPerson.Position = Vector3.new(15.23, 5.5, 207.43)
		debounce = false
		wait(60)
		debounce = true
		script.Parent.BrickColor = BrickColor.new('Medium stone grey')
		end
end)

2 comments

0

try using if debounce == false or changing the wait time

0

@ProqrammedGreen "not debounce" and "debounce == false" are the same. Changing the wait time won't make a difference.

1 answer

✓ Accepted answer

At the very end of the script, you set debounce=true, which will make not debounce false, preventing execution of your code on a touched event.

However, that is not the main issue.

There is an error on line 13, when you try to set clonedPerson.Position. Presumably, the avatar is the character model, and models do not have a position value. If you want to move the character to a location, you must set Character.HumanoidRootPart.Position.

This error stops execution of the code before it reaches debounce=false, which means that the debounce will prevent the cloning from happening again.

1 comment

0

Thank you, this was it

This discussion is preserved as it was. New answers, comments, and votes are closed.