Correct me if I'm wrong, but I think you gotta define the variable "Debounce" outside of the function.
local Debounce = false
script.Parent.Touched:Connect(function(hit)
if Debounce then return end
Debounce = true
local model = game.Workspace.MALP
if hit == model.Part1 then
model:MoveTo(Vector3.new(-335.75, 31.154, -985.621))
end
Debounce = false
end
end)
Made the script look a little more cleaner, but I hope you understand how debounce is used. Another thing to have in your head while programming is the use of variables.
You made this:
local model = game.Workspace.MALP
if hit == game.Workspace.MALP.Part1 then
model:MoveTo(Vector3.new(-335.75, 31.154, -985.621))
end
To make the script a little cleaner you can use the model that you just defined with a variable to make shorter lines like this:
local model = game.Workspace.MALP
if hit == game.Workspace.MALP.Part1 then
local model = game.Workspace.MALP
if hit == model.Part1 then
I hope this helped you out. Just comment if there's anything you're wondering about or if it's something i've done wrong.
Waterfox
1 comment
If you will be using Debounce in many of your scripts, consider making a module/function that does this for you (i.e. https://developer.roblox.com/articles/Debounce at "Advanced Notation")