Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Touched event brick only works once?

Asked by 4 years ago

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)
0
try using if debounce == false or changing the wait time proqrammed 285 — 4y
0
@ProqrammedGreen "not debounce" and "debounce == false" are the same. Changing the wait time won't make a difference. Rinpix 639 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

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.

0
Thank you, this was it NxvaRBLX 16 — 4y
Ad

Answer this question