Hey all, I am making this gate code but I don’t know why I am getting this error. Please help.
Note: I am not great with coding so don’t judge me.
Hey all, I am making this gate code but I don’t know why I am getting this error. Please help.
Note: I am not great with coding so don’t judge me.
use Vector3.new
if gate.Position == Vector3.new(-21.5, 12.625, -79,75) then
I am not getting an error but the down tween doesn’t play.
Again, I am not good at coding as I am still learning.
My code also:
local gate = game.Workspace.Doors.Gate1.Gate
local status = game.Workspace.Values.Status
local label = script.Parent.Status.SurfaceGui.TextLabel
local button = script.Parent.Open.ClickDetector
local ts = game:GetService("TweenService")
local info = TweenInfo.new(10)
local p = {Position = Vector3.new(-21.5, 15.625, -79.75)}
local r = {Position = Vector3.new(-21.5, 6.5, -79.75)}
local up = ts:Create(gate, info, p)
local down = ts:Create(gate, info, r)
button.MouseClick:Connect(function()
up:Play()
end)
button.MouseClick:Connect(function()
if gate.Position == Vector3.new(-21.5, 12.625, -79,75) then
down:Play()
else
up:Play()
end
end)
if gate.Position == Vector3.new(-21.5, 12.625, -79,75) then
down:Play()
elseif gate.Position == Vector3.new(-21.5, 6.5, -79.75) then
up:Play()
end
Isn’t it better to use else instead of elseif?
Sorry, it still doesn’t work.
Here’s my code:
local gate = game.Workspace.Doors.Gate1.Gate
local status = game.Workspace.Values.Status
local label = script.Parent.Status.SurfaceGui.TextLabel
local button = script.Parent.Open.ClickDetector
local ts = game:GetService("TweenService")
local info = TweenInfo.new(10)
local p = {Position = Vector3.new(-21.5, 15.625, -79.75)}
local r = {Position = Vector3.new(-21.5, 6.5, -79.75)}
local up = ts:Create(gate, info, p)
local down = ts:Create(gate, info, r)
button.MouseClick:Connect(function()
if gate.Position == Vector3.new(-21.5, 12.625, -79,75) then
down:Play()
elseif gate.Position == Vector3.new(-21.5, 6.5, -79.75) then
up:Play()
end
end)
got a little idea:
instead of checking gates position you could check bool value
this might work
local gate = game.Workspace.Doors.Gate1.Gate
local status = game.Workspace.Values.Status
local label = script.Parent.Status.SurfaceGui.TextLabel
local button = script.Parent.Open.ClickDetector
local open = false
local ts = game:GetService("TweenService")
local info = TweenInfo.new(10)
local p = {Position = Vector3.new(-21.5, 15.625, -79.75)}
local r = {Position = Vector3.new(-21.5, 6.5, -79.75)}
local up = ts:Create(gate, info, p)
local down = ts:Create(gate, info, r)
button.MouseClick:Connect(function()
if open then
down:Play()
else
up:Play()
end
end)
This is the correct way to do this, however you don’t change the boolean when the gate is open,i.e.
button.MouseClick:Connect(function()
if open then
down:Play()
open = false;
else
up:Play()
open = true;
end
end)
open and status looks like used already.
And, what’s object’s initial position?
Status is for later in the code. It’s for a screen that shows whether the gate is opened or closed.
You could just use that instead of open
. Is the status value a boolean or something else?
Yours kind of worked but I did it a different way.
Here’s my code:
button.MouseClick:Connect(function()
if gate.Position == Vector3.new(-21.5, 15.625, -79.75) then
open = true
down:Play()
elseif gate.Position == Vector3.new(-21.5, 6.5, -79.75) then
open = false
up:Play()
end
end)
So, basically, the code works now.
I’ll mark yours as the solution because it was close to my code.
You don’t need to check the doors position, the open
boolean tells you the position by it’s very nature (up = true, down = false).
button.MouseClick:Connect(function()
open = not open
if open then up:Play() else down:Play() end
end)
Always better to code with the compound operator (makes it more readable since all the information is on the same line). However, I try to keep the code as close to the original to save over complicating the solution. Not one like given to anyone, man you must be the harshest of critics!