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

Why is the player spawning on default spawn? [Unsolved]

The script is supposed to make the player's team change when the value called "mech" changes. Unfortunately, the player is staying neutral, and is spawning at default spawn! Why is that happening? here is the script

while true do
    wait(0.1)
    if script.Parent.Parent.MechValue.Value == 1 then
        script.Parent.Parent.Parent.Parent.Neutral =  false
        script.Parent.Parent.Parent.Parent.TeamColor = BrickColor.new("Institutional white")
        print("Picked white")
    elseif script.Parent.Parent.MechValue.Value == 2 then
        script.Parent.Parent.Parent.Parent.Neutral =  false
        script.Parent.Parent.Parent.Parent.TeamColor = BrickColor.new("Medium stone gray")
        print("Picked gray")
    elseif script.Parent.Parent.MechValue.Value == 3 then
        script.Parent.Parent.Parent.Parent.Neutral =  false
        script.Parent.Parent.Parent.Parent.TeamColor = BrickColor.new("Really black")
        print("Picked black")
    end
end

Please help!!! Thank you!!! OUTPUT:Players.Player.PlayerGui.ScreenGui.TextButton.Script:17: 'end' expected (to close 'while' at line 1) near ''

3 comments

1

Does the script print something and what's its location?

1

Also, I suggest using elseifs.

0

its location is inside a screenGUI, inside a textbutton

1 answer

[EDIT: Fixed if error] First, let's clean up your code with a little tabbing. Next, use elseifs instead of multiple if statements. Lastly, players have a Neutral value that defaults to True, so you must set it to False to allow players to change teams.

Code that reflects changes:

while true do
	wait(0.1)
	if script.Parent.Parent.MechValue.Value == 1 then
		script.Parent.Parent.Parent.Parent.Neutral =  false
		script.Parent.Parent.Parent.Parent.TeamColor = BrickColor.new("Institutional white")
		print("Picked white")
	elseif script.Parent.Parent.MechValue.Value == 2 then
		script.Parent.Parent.Parent.Parent.Neutral =  false
		script.Parent.Parent.Parent.Parent.TeamColor = BrickColor.new("Medium stone gray")
		print("Picked gray")
	elseif script.Parent.Parent.MechValue.Value == 3 then
		script.Parent.Parent.Parent.Parent.Neutral =  false
		script.Parent.Parent.Parent.Parent.TeamColor = BrickColor.new("Really black")
		print("Picked black")
	end
end

Also, next time, if this is all the code in the script, I suggest using game.Players.LocalPlayer within a LocalScript instead to reduce the amount of parents.

10 comments

1

Ah, had completely forgotten the Neutral option. Hope this helps the OP.

0

It didn't help, it makes sense, and the neutral part is definitely important but it didn't work!

1

Are the parent's correctly oriented and is it printing anything?

1

I fixed the script, I forgot to change an if, let me know if it works now

0

ok, it is changing the teams now, but still going to nuetral spawn

1

Do the SpawnLocations have the right TeamColor properties as well?

0

Yes I think so, the block color is right, and then TeamColor is the same color (I.E Institutional white)

1

Peculiar case then. Are you testing it online? Sometimes it bugs (or at least used to bug) in other modes.

0

doesn't work for either, although thanks for telling me because apparently my camera script doesn't work!

0

Spawn locations also have a Neutral Value! Make sure it is false!

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