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

why do i keep getting "Error:(22,1)Expected identifier,got 'if'"?

Hi i have a problem with my script.I was trying to make the script where i want it to make players from 4 different teams spawn with a default npc that is that different from other teams for example for team xbox i want them to have a default npc for those players that are in that team that looks different from from the other team default npc.Do i need to be more specific in this script?Did i put things i don't need in the script?I'm still a beginner at scripting and still trying to understand the language of lua in roblox and couldn't find what i was looking for on google or youtube so i gave it a try on making my own script.I really would appreciate it if you guys could help me out on this thanks.

--Variables for teams
local Team = game.Teams.Xbox
local Team = game.Teams.Playstation
local Team = game.Teams.Nintendo
local Team = game.Teams.PC

--Variables for Team spawns
local spawns = game.workspace.Nintendo.Nspawns
local spawns = game.workspace.PC.PCspawns
local spawns = game.workspace.Playstation.PSspawns
local spawns = game.workspace.Xbox.Xspawns

--Variables for TeamNpc
local TeamDefaultNPC = game.StarterPlayer.XboxNpc
local TeamDefaultNPC = game.StarterPlayer.PlaystationNpc
local TeamDefaultNPC = game.StarterPlayer.PcNPC
local TeamDefaultNPC = game.StarterPlayer.NintendoNPC
--Player Variable
local StarterPlayer = game.StarterPlayer.Humanoid

function 
if local spawn = game.workspace.Pc.PCspawns then StarterPlayer = game.StarterPlayer.PcNPC end
if local spawn = game.workspace.xbox.Xspawns then StarterPlayer = game.StarterPlayer.XboxNpc end
if local spawn = game.workspace.Nintendo.Nspawns then StarterPlayer = game.StarterPlayer.NintendoNPC end
if local spawn = game.workspace.Playstation.PSspawns then StarterPlayer = game.StarterPlayer.PlaystationNpc end

end

2 comments

0

remove local from line 22-26 after if

0

hmm...i fixed my code that doesnt have errors thanks to you,but it didn't function as i expected to see,the starter player still uses a custom character instead of  the default characters i made

1 answer

✓ Accepted answer

Remove the locals, they make the script not work. Plus, always that you are defining a function, you must put the name of it and the arguments inside the (), which can be none.

Using elseifs will avoid running unnecessary lines of code and is the "best" way to do more than one if, especially if you don't want two to "overlap"

--Variables for teams
local Team = game.Teams.Xbox
local Team = game.Teams.Playstation
local Team = game.Teams.Nintendo
local Team = game.Teams.PC

--Variables for Team spawns
local spawns = game.workspace.Nintendo.Nspawns
local spawns = game.workspace.PC.PCspawns
local spawns = game.workspace.Playstation.PSspawns
local spawns = game.workspace.Xbox.Xspawns

--Variables for TeamNpc
local TeamDefaultNPC = game.StarterPlayer.XboxNpc
local TeamDefaultNPC = game.StarterPlayer.PlaystationNpc
local TeamDefaultNPC = game.StarterPlayer.PcNPC
local TeamDefaultNPC = game.StarterPlayer.NintendoNPC
--Player Variable
local StarterPlayer = game.StarterPlayer.Humanoid

function myFunction ()
	if spawn == game.workspace.Pc.PCspawns then
		StarterPlayer == game.StarterPlayer.PcNPC
	elseif local spawn == game.workspace.xbox.Xspawns then
		StarterPlayer == game.StarterPlayer.XboxNpc
	elseif local spawn == game.workspace.Nintendo.Nspawns then
		StarterPlayer == game.StarterPlayer.NintendoNPC
	elseif local spawn == game.workspace.Playstation.PSspawns then
		StarterPlayer == game.StarterPlayer.PlaystationNpc
	end
end

EDIT: I forgot, you were using = instead of ==. To check if a value is equal to, then use ==.

4 comments

0

thank you so much for the help, theres an error in line 22, the error is "Error:{22,10} Expected'then',got '='"

0

Sorry, read again the answer, I edited it. should be now working.

0

thank you so much

0

hmm...i fixed my code that doesnt have errors thanks to you,but it didn't function as i expected to see,the starter player still uses a custom character instead of the default characters i made

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