So I wrote a code to have a GUI click to teleports players into a train car seat. But it shows this error keep popping up.
Error: 14:39:01.992 - Players.Player.PlayerGui.ScreenGui.LocalScript:14: 'then' expected near '<eof>'
Script:
01 | local Track 1 = script.Parent.Background:WaitForChild( "Track1" ) |
02 | local Track 3 = script.Parent.Background:WaitForChild( "Track3" ) |
03 | local Track 4 = script.Parent.Background:WaitForChild( "Track4" ) |
04 | local player = game.Players.LocalPlayer |
05 |
06 | if script.Parent.Track 1. MouseButton 1 Click:connect( function () |
07 | torso = player.Character:WaitForChild( "Torso" ) |
08 | humanoid = player.Character:WaitForChild( "Humanoid" ) |
09 | if torso and humanoid then |
10 | torso.CFrame = CFrame.new(game.Workspace.R 62 _Trk 1. Model.VehicleSeat + Vector 3. new( 0 , 3 , 0 )) |
11 | script.Parent.Background:Destroy() |
12 | end |
13 | end ) |
Events don't need to be used as conditionals [actually, they shouldn't be in general]
Merely remove the 'if' in front of the event declaration on line 06.
Also, you can't add an objectvalue to a Vector3 directly, so you must state that you want the 'VehicleSeat's position.
01 | local Track 1 = script.Parent.Background:WaitForChild( "Track1" ) |
02 | local Track 3 = script.Parent.Background:WaitForChild( "Track3" ) |
03 | local Track 4 = script.Parent.Background:WaitForChild( "Track4" ) |
04 | local player = game.Players.LocalPlayer |
05 |
06 | script.Parent.Track 1. MouseButton 1 Click:connect( function () |
07 | torso = player.Character:WaitForChild( "Torso" ) |
08 | humanoid = player.Character:WaitForChild( "Humanoid" ) |
09 | if torso and humanoid then |
10 | torso.CFrame = CFrame.new(workspace [ "R62_Trk1" ] .Model.VehicleSeat.Position + Vector 3. new( 0 , 3 , 0 )) |
11 | script.Parent.Background:Destroy() |
12 | end |
13 | end ) |