Because when I bring the model to the position, it still lags and bounces around.
01 | script.Parent.Touched:Connect( function (hit) |
02 | local debounce = true |
03 | if debounce then |
04 | debounce = false |
05 | local model = game.Workspace.MALP |
06 | if hit = = game.Workspace.MALP.Part 1 |
07 | then |
08 | model:MoveTo(Vector 3. new(- 335.75 , 31.154 , - 985.621 )) |
09 | end |
10 | end |
11 | debounce = true |
12 | end ) |
For context, I am moving a car to this position. It does not lag or bounce around before I bring it to the destination.
Correct me if I'm wrong, but I think you gotta define the variable "Debounce" outside of the function.
01 | local Debounce = false |
02 |
03 | script.Parent.Touched:Connect( function (hit) |
04 | if Debounce then return end --Checking if the variable is true. If not, continue. |
05 | Debounce = true --Now debounce is true and firing this function will stop the code at the line above |
06 | local model = game.Workspace.MALP |
07 | if hit = = model.Part 1 then |
08 | model:MoveTo(Vector 3. new(- 335.75 , 31.154 , - 985.621 )) |
09 | end |
10 | Debounce = false --Now the code in the function is ready to be fired again. |
11 | end |
12 | 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:
1 | local model = game.Workspace.MALP |
2 | if hit = = game.Workspace.MALP.Part 1 then |
3 | model:MoveTo(Vector 3. new(- 335.75 , 31.154 , - 985.621 )) |
4 | 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:
1 | local model = game.Workspace.MALP |
2 | if hit = = game.Workspace.MALP.Part 1 then |
3 |
4 | --To This VVV |
5 |
6 | local model = game.Workspace.MALP |
7 | if hit = = model.Part 1 then --This line got shorter |
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.