How to make a Toll Gate System?

  1. What do you want to achieve?

I want a gate system where the gate opens upright and straight(at an angle of 90 degrees).

  1. What is the issue?

I tried to make a toll gate system, using the script which is embedded below this message but the gate doesn’t seem to work as intended. I want it to open up straight, but it seems to be a bit inclined. As I am not not a professional scripter, I cannot identify the error.

  1. What solutions have you tried so far?

I have tried to look for solutions on the internet as well as the Developer Forum, but could not find any answers that meet my demands.

The Script:

local gate = workspace:WaitForChild("Right Gate")
local maingate = gate:WaitForChild("Gate2")
local gatepart = maingate:WaitForChild("Gate")
local button = workspace:WaitForChild("RightButton"):WaitForChild("Button"):WaitForChild("ProximityPrompt")
local newPos = CFrame.Angles(math.deg(0), math.deg(-90), math.deg(-90))


button.Triggered:Connect(function()
    gatepart.Position = Vector3.new(424.512, 5.14, -843.48)
    gatepart.CFrame = CFrame.new(gatepart.Position) *  newPos
    
    print("yes")
end)

Outcome:
robloxapp-20240424-0803387.wmv (1.7 MB)

Try changing

local newPos = CFrame.Angles(math.deg(0), math.deg(-90), math.deg(-90))

to:

local newPos = CFrame.Angles(0, math.rad(-90), math.rad(-90))

the code above is assuming you are trying to go off of degrees and not radians.

math.deg will convert radians to degrees while math.rad converts degrees to radians.

P.S: Whenever you have a value of 0 you don’t need to convert it, you can just leave it at 0 as shown in the code above.

Is there any way I can make it move smoothly?

You can use tween service

local TweenService = game:GetService(“TweenService”)
local Part = game.Workspace.Part – Replace with your object you want to move
local Tween = TweenService:Create(
Part,
TweenInfo.new(1), – Replace with your tween time (how long it takes to get to the position)
{Position = Vector3.new(0,0,0)} – Replace with your end position
)

Tween:Play()

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.