I am trying to make my door slide up when a Text button on a surfaceGui is clicked on. Here is my script:
local door = game.Workspace.DoorSpawn7
local newPos = door.Position + Vector3.new(0,40,0) -- the position the Part will go to
local Time = 10 -- the time that the script will take to move the part
local Increment = 0.5 -- the Part will move 0.5 studs each time it moves
local Debounce = false
local Diff = newPos - door.Position -- the difference between the two positions
local Mag = Diff.magnitude -- the distance between the two parts
local Direction = CFrame.new(door.Position, newPos).lookVector
local TxtBox = door.SurfaceGui.TextLabel
function onTouch(door) -- The function that runs when the button is clicked.
if Debounce then return end
Debounce = true
TxtBox = 'Door Is Now Openning...'
for n = 0, Mag, Increment do
door.CFrame = door.CFrame + (Direction * Increment)
wait( (Time/Mag) * Increment )
end
Debounce = false
end
script.Parent.MouseButton1Click:connect(onTouch)
I'm not sure what the error is. I'm new to LUA but have experience with other scripting languages (javascript.) Also, I looked up this error, and found a Related Question similar to the problem i'm having. What I understood from the answer and other commenters who answered to the error. Is that for example, you can't change the meaning of a variable and then try to get the original by calling it back but instead get the changed one, probably not the best example but hopefully this was enough information to help solve the problem and know where I stand in my understanding of this error. Thank you for your help in advance, Addictedroblox1414.

1 comment
There is a function in my script called onTouch. I'm not sure what you mean by to try adding a function.