#Open/Close gate
18 messages · Page 1 of 1 (latest)
e
Easy setup guide for noobies:
- Insert a script into the proximity prompt.
- create 2 locals called isGateOpen and isTweening, set both to false.
- Create 2 new tweens for opening and closing the gates.
- Use the .Trigged event to connect to a new function.
- in the new function, put an if statement to disable tweens to activate while a tween is already running.
if isTweening then return end - After that if statement insert another if statement for opening and closing the gate.
- Set isTweening to true, play the tween, wait for it to finish, set isTweening to false and isGateOpen to
isGateOpen = not isGateOpen. (Same for closing the gate)
Here's an AI generated code that followed those specific instructions:
local isGateOpen = false
local isTweening = false
local openTween = game:GetService("TweenService"):Create(
script.Parent.Gate, -- Object to tween
TweenInfo.new(1, Enum.EasingStyle.Quad, Enum.EasingDirection.Out), -- Tween info
{CFrame = script.Parent.Gate.CFrame * CFrame.new(0, 0, -5)} -- Goal properties
)
local closeTween = game:GetService("TweenService"):Create(
script.Parent.Gate,
TweenInfo.new(1, Enum.EasingStyle.Quad, Enum.EasingDirection.Out),
{CFrame = script.Parent.Gate.CFrame * CFrame.new(0, 0, 5)}
)
script.Parent.ProximityPrompt.Triggered:Connect(function()
if isTweening then return end
if isGateOpen then
isTweening = true
closeTween:Play()
closeTween.Completed:Wait()
isTweening = false
isGateOpen = not isGateOpen
else
isTweening = true
openTween:Play()
openTween.Completed:Wait()
isTweening = false
isGateOpen = not isGateOpen
end
end)
Overall this should be a good stable script, beware though this is the most basic solution and not the most advanced and preferable.
Tween can cause lag when it runs over the server, it is advised to run into the client instead.
2 locals? 🤔
vars (variables) 😉
I don't see the problem with the definition of variables as locals in my guide.
In the end it's assigning a local variable, I better think to say local so we won't mean a global variable.
Just basically you can have 3 parts, the door, the visually none moving frame, and a transparent fram which moves and you can use angles for better and smoother results
At least i find it that way
(of course weld them all together)
Besides the none moving part
And in frame i mean a door frame
I don't mind the method to move the gate, as long it runs on all clients with a cool down, distance verification and anti spam detection.
Yeah
With tween.