Script under StarterPlayerScripts not running?

I have a normal script under StarterPlayerScripts that’s supposed to get detect if your team is Team1 (yes I have the player’s team seat to Team1), but for some reason nothing happens when I play test the game, no errors or anything

a bulleted to be clear because sometimes people don’t read what I write thoroughly

  • NORMAL script
  • script under StarterPLAYERScripts
  • the player’s team is Team1
  • nothing printed and no errors in output
if script.Parent.Parent.Team == "Team1"
then
	print("team1")
	--and do other stuff
end

I also tried just doing a simple print("hello world!") and nothing happened

muahaha with my master script hijacking skills I made this

local Players = game:GetService("Players")
 
Players.PlayerAdded:Connect(function(player)
	if player.Team == game.Teams.Helthee then
		print(player.Team)
		--do stuff
	end
end)

from PlayerAdded

help is much appreciated :happy3:

Holup theres a coefficients emoticon??? :coefficients: :coefficients: :coefficients: :coefficients: :coefficients: :coefficients: :coefficients: :coefficients: :coefficients: :coefficients:

If the script’s under StarterPlayerScripts, why are you doing script.Parent.Parent?
Also, you should compare the Team with a team object, not a string.

Edit: Nevermind, it’ll be parented to PlayerScripts, inside the Player.

Team property is actually a reference to the team object, so do:

if script.Parent.Parent.Team == game.Teams.Team1 then

end

the player is what script.parent.parent is

You should make a variable which

local player = game.players.localplayer

or

local player = game.players.playeradded

But the script will be parented to the player, so script.Parent should be enough.

no, actually the script will be parented to PlayerScripts which is a child of Player

Oh, my bad. (30 charsssssssssssssssssss)

Actually, LocalPlayer can only be used inside LocalScripts. PlayerAdded is a RBXScriptSignal, and you’d actually have to use :Connect() with it.

Wait a second, I don’t even think the script is running at all, I tried just doing a simple print("hello world!") but nothing happened

Oh, I’m pretty sure only LocalScripts are allowed in StarterPlayerScripts.

Edit: 100% sure. Script don’t appear when i press the plus on StarterPlayerScripts.

Oh, so then how would I make a normal script check what a player’s team is (spoiler alert I want to clone a gear into their inventory)

You can do it in ServerScriptService, and listen for PlayerAdded.

2 Likes

It is because you didn’t add OnPlayerEntered verible.

The only scripts that will run in StarterPlayerScripts are LocalScripts and they’re the only ones that should be in there as well. StarterPlayerScripts populates PlayerScripts, which is a client-side container under the Player object for running code much like ServerScriptService is for the server.

When you are checking for the player’s team, Team == "Team1" will fail. The team property of the player is a reference to a team instance and an instance cannot be equal to a string. The way to fix this is either to add .Name to Team so that you’re comparing the name of the team instance to a string or changing the second operand to reference the actual team at game:GetService("Teams").Team1.

For PlayerAdded, LocalScripts will only start executing after the server finishes replicating the initial DataModel snapshot. PlayerAdded for the current client will already have fired by then, so when a LocalScript connects to PlayerAdded, the current client will have already been in the server. When needing to act with the LocalPlayer, just find it under the Players service. PlayerAdded in LocalScripts is only for working with when other players join the server.

6 Likes