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
Remove the local
s, 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 elseif
s 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 ==
.