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

Expected 'then' when parsing if statement, got '='. What can i do to fix this?

Hi peeps. I am trying to make one of those camping games. (im a beginner lol) and this script is not working.... Its a script where the player touches a part (the part's name is TeleportPad) and they get teleported to the Van (there is a part named Van, and a model named theREALVan is inside of it) and then they are supposed to go to an open seat, that is not occupied by another player. So um yeah here is the script

local seat1 = workspace.Map.Van.theREALVan.BackSeats.seat1
local seat2 = workspace.Map.Van.theREALVan.BackSeats.seat2
local seat3 = workspace.Map.Van.theREALVan.BackSeats.seat3
local seat4 = workspace.Map.Van.theREALVan.BackSeats.seat4
local seat5 = workspace.Map.Van.theREALVan.BackSeats.seat5
local seat6 = workspace.Map.Van.theREALVan.BackSeats.seat6


if seat1.Occupant = "" then
seat1 = openseat
elseif seat2.Occupant = "" then
seat2 = openseat
elseif seat3.Occupant = "" then
seat3 = openseat
elseif seat4.Occupant = "" then
seat2 = openseat
elseif seat5.Occupant = "" then
seat3 = openseat
elseif seat5.Occupant = "" then
seat3 = openseat

local part = script.Parent
function onTouched(part)
local character = game.Workspace.Player
local player = game.Players:GetPlayerFromCharacter(character)
character.Position = workspace:FindFirstChild("openseat").Position
end
part.Touched:Connect(function()
end

I have no idea what is wrong with this. Help would be greatly appreciated :3

5 comments

0

(CREDIT TO raid6n for the script)

0

Could you post the full script?

0

This is the full script I just made changes

0

output*

0

Answered nevermind

2 answers

First error was you need two == instead of one = is for assigning values to variables, == is for comparing

Your other error was that you were missing a parenthesis at the end of your script. (line 29 of your question)

When creating a touch event, you can either write it two ways:

function onTouched(hit)
	print(hit.Name .. " was touched")
end

part.Touched:Connect(onTouched)

or you can write it like this:

part.Touched:Connect(function(hit)
	print(hit.Name .. " was touched")
end)

part.Touched:Connect() means you are connecting (running) the function inside the parenthesis when the part is touched.

This will still error because you never told the script what openseat is, but the rest of the errors are gone so we can celebrate that!!. Can you tell me what open seat is so we can continue making the script?

local seat1 = workspace.Map.Van.theREALVan.BackSeats.seat1
local seat2 = workspace.Map.Van.theREALVan.BackSeats.seat2
local seat3 = workspace.Map.Van.theREALVan.BackSeats.seat3
local seat4 = workspace.Map.Van.theREALVan.BackSeats.seat4
local seat5 = workspace.Map.Van.theREALVan.BackSeats.seat5
local seat6 = workspace.Map.Van.theREALVan.BackSeats.seat6


if seat1.Occupant == "" then
	seat1 = openseat
elseif seat2.Occupant == "" then
	seat2 = openseat
elseif seat3.Occupant == "" then
	seat3 = openseat
elseif seat4.Occupant == "" then
	seat2 = openseat
elseif seat5.Occupant == "" then
	seat3 = openseat
elseif seat5.Occupant == "" then
	seat3 = openseat
end


local part = script.Parent

function onTouched(part)
	local player = game.Players:FindFirstChild(part.Parent.Name)
	if player then
		local character = player.Character 
		character.Position = workspace:FindFirstChild("openseat").Position
	end
end

part.Touched:Connect(onTouched)

#WORKING (HOPEFULLY) ANSWER: Here's a answer that should work. I haven't tested it so let me know if it doesn't.

--get all the seats in the backseats model and put them into a variable called a table
local seats = workspace.Map.Van.theREALVan.BackSeats:GetChildren()
local part = script.Parent

--when the part is touched, this function gets ran
function onTouched(part)
	--check if a player is touching the part
	local player = game.Players:FindFirstChild(part.Parent.Name)

	--if a player is touching the part, then...
	if player then
		local character = player.Character 
		character.Position = workspace:FindFirstChild("openseat").Position
		
		--go through all the seats and find the first seat that isn't occupied.
		for _, seat in pairs(seats)do
			if not seat.Occupant then
				--sit in seat and exit out of function
				seat:Sit(character.Humanoid)
				return
			end 
		end
	end
end

part.Touched:Connect(onTouched)

7 comments

0

i think character.Position = workspace:FindFirstChild("openseat").Position should becharacter.Position = workspace:FindFirstChild(openseat).Position

0

upvoted as you did a great job explaining

0

so did you, mr. speedy :)

0

lmao

0

thanks for eding my answer, i forgot to put that there xd

0

edited the post. let me know if that works.

0

pls respond :(

you need two == instead of one = is for assigning values to variables, == is for comparing


if seat1.Occupant = "" then
seat1 = openseat
elseif seat2.Occupant = "" then
seat2 = openseat
elseif seat3.Occupant = "" then
seat3 = openseat
elseif seat4.Occupant = "" then
seat2 = openseat
elseif seat5.Occupant = "" then
seat3 = openseat
elseif seat5.Occupant = "" then
seat3 = openseat

should be


if seat1.Occupant == "" then
seat1 = openseat
elseif seat2.Occupant == "" then
seat2 = openseat
elseif seat3.Occupant == "" then
seat3 = openseat
elseif seat4.Occupant == "" then
seat2 = openseat
elseif seat5.Occupant == "" then
seat3 = openseat
elseif seat5.Occupant == "" then
seat3 = openseat

New script:

local seat1 = workspace.Map.Van.theREALVan.BackSeats.seat1
local seat2 = workspace.Map.Van.theREALVan.BackSeats.seat2
local seat3 = workspace.Map.Van.theREALVan.BackSeats.seat3
local seat4 = workspace.Map.Van.theREALVan.BackSeats.seat4
local seat5 = workspace.Map.Van.theREALVan.BackSeats.seat5
local seat6 = workspace.Map.Van.theREALVan.BackSeats.seat6

if seat1.Occupant == "" then
	seat1 = openseat
elseif seat2.Occupant == "" then
	seat2 = openseat
	elseif seat3.Occupant == "" then
	seat3 = openseat
	elseif seat4.Occupant == "" then
	seat4 = openseat
	elseif seat5.Occupant == "" then
	seat5 = openseat
		elseif seat6.Occupant == "" then
	seat6 = openseat

local part = script.Parent
function onTouched(part)
local player = game.Players:FindFirstChild(part.Parent.Name)
    if player then
        local character = player.Character 
	character.FindFirstChild("Humanoid").Position = workspace:FindFirstChild(openseat).Position
end

part.Touched:Connect(part)
end

5 comments

0

Okay now its saying to close something at line 29 (the full script)

0

ill help in a minute

0

and the error is?

0

check my answer. we still need to figure out what openseat is. can you let me know what you're trying to do

0

I believe she is trying to making a camping game, when there is no one in the seat she gets teleported to it and when seat1 is full it will make seat2 an openseats and so on

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