Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How can I get rid of this error?

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:

local Track1 = script.Parent.Background:WaitForChild("Track1")
local Track3 = script.Parent.Background:WaitForChild("Track3")
local Track4 = script.Parent.Background:WaitForChild("Track4")
local player = game.Players.LocalPlayer

if script.Parent.Track1.MouseButton1Click:connect(function()
	torso = player.Character:WaitForChild("Torso")
	humanoid = player.Character:WaitForChild("Humanoid")
	if torso and humanoid then
		torso.CFrame = CFrame.new(game.Workspace.R62_Trk1.Model.VehicleSeat + Vector3.new(0, 3, 0))
		script.Parent.Background:Destroy()
	end
end)

1 comment

1

Remove the 'if' on line 06.

1 answer

✓ Accepted answer

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.

local Track1 = script.Parent.Background:WaitForChild("Track1")
local Track3 = script.Parent.Background:WaitForChild("Track3")
local Track4 = script.Parent.Background:WaitForChild("Track4")
local player = game.Players.LocalPlayer

script.Parent.Track1.MouseButton1Click:connect(function()
    torso = player.Character:WaitForChild("Torso")
    humanoid = player.Character:WaitForChild("Humanoid")
    if torso and humanoid then
        torso.CFrame = CFrame.new(workspace["R62_Trk1"].Model.VehicleSeat.Position + Vector3.new(0, 3, 0))
        script.Parent.Background:Destroy()
    end
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.