hey devs this is what I want to achieve:-
an drivable train with screen gui containing throttle bar, brake bar, horn button, headlight button, forward/Reverse switch, exit button
Here is code;-
-- Variables
local Throttle = 0 -- Represents the current throttle value
local Brake = 0 -- Represents the current brake value
local HornSound = "rbxassetid://123456789" -- Replace with the ID of your horn sound
local HeadlightState = false -- Represents the current state of the headlight
local Direction = 1 -- Represents the current direction (1 for forward, -1 for reverse)
-- GUI Setup
local Player = game.Players.LocalPlayer
local PlayerGui = Player:WaitForChild("PlayerGui")
local ScreenGui = Instance.new("ScreenGui")
ScreenGui.Parent = PlayerGui
-- Throttle Bar
local ThrottleBar = Instance.new("Frame")
ThrottleBar.Size = UDim2.new(0, 200, 0, 20)
ThrottleBar.Position = UDim2.new(0.5, -100, 0.8, -10)
ThrottleBar.BackgroundColor3 = Color3.fromRGB(0, 255, 0)
ThrottleBar.BorderSizePixel = 0
ThrottleBar.Parent = ScreenGui
-- Brake Bar
local BrakeBar = Instance.new("Frame")
BrakeBar.Size = UDim2.new(0, 200, 0, 20)
BrakeBar.Position = UDim2.new(0.5, -100, 0.85, -10)
BrakeBar.BackgroundColor3 = Color3.fromRGB(255, 0, 0)
BrakeBar.BorderSizePixel = 0
BrakeBar.Parent = ScreenGui
-- Horn Button
local HornButton = Instance.new("TextButton")
HornButton.Size = UDim2.new(0, 80, 0, 30)
HornButton.Position = UDim2.new(0.5, -40, 0.9, -15)
HornButton.Text = "Horn"
HornButton.Parent = ScreenGui
-- Headlight Button
local HeadlightButton = Instance.new("TextButton")
HeadlightButton.Size = UDim2.new(0, 80, 0, 30)
HeadlightButton.Position = UDim2.new(0.5, 50, 0.9, -15)
HeadlightButton.Text = "Headlight"
HeadlightButton.Parent = ScreenGui
-- Forward/Reverse Switch
local Switch = Instance.new("TextButton")
Switch.Size = UDim2.new(0, 80, 0, 30)
Switch.Position = UDim2.new(0.5, -40, 0.95, -15)
Switch.Text = "Forward"
Switch.Parent = ScreenGui
-- Exit Button
local ExitButton = Instance.new("TextButton")
ExitButton.Size = UDim2.new(0, 80, 0, 30)
ExitButton.Position = UDim2.new(0.5, 50, 0.95, -15)
ExitButton.Text = "Exit"
ExitButton.Parent = ScreenGui
-- Functions
local function UpdateThrottleBar()
ThrottleBar.Size = UDim2.new(Throttle, 0, 0, 20)
end
local function UpdateBrakeBar()
BrakeBar.Size = UDim2.new(Brake, 0, 0, 20)
end
local function ToggleHeadlight()
HeadlightState = not HeadlightState
-- Add logic to control train's headlights based on HeadlightState
end
local function ToggleDirection()
Direction = -Direction
if Direction == 1 then
Switch.Text = "Forward"
else
Switch.Text = "Reverse"
end
end
local function PlayHorn()
-- Add logic to play the horn sound
end
local function ExitTrain()
-- Add logic to remove the GUI and stop the train
ScreenGui:Destroy()
end
-- GUI Event Connections
ThrottleBar:GetPropertyChangedSignal("Size"):Connect(function()
Throttle = ThrottleBar.Size.X.Offset / 200
end)
BrakeBar:GetPropertyChangedSignal("Size"):Connect(function()
Brake = BrakeBar.Size.X.Offset / 200
end)
HornButton.MouseButton1Click:Connect(PlayHorn)
HeadlightButton.MouseButton1Click:Connect(ToggleHeadlight)
Switch.MouseButton1Click:Connect(ToggleDirection)
ExitButton.MouseButton1Click:Connect(ExitTrain)
will this work??