local role = Instance.new("StringValue") role.Name = "Rank" role.Value = player:GetRoleInGroup(4539848) if role.Value = "dab" then function onPlayerEntered(plr) plr.TeamColor = BrickColor.new("Bright red") plr:LoadCharacter() end end game.Players.PlayerAdded:connect(onPlayerEntered) end
So whenever you created the role, you did it the wrong way. What you did was just create it, doesn't put it inside of anything tho. I would recommend you put it inside of the player. It might work better. I will write an example and explain it:
game.Players.PlayerAdded:Connect(function(Player) -- Fired whenever someone joins the game. local role = Instance.new("StringValue") -- Creates the string value of "role" role.Name = "Role" -- Names the role string role.Value = Player:GetRoleInGroup(4539848) -- Checks the group role and sets the value. role.Parent = Player -- Moves the string value inside the player instance. wait() -- Waits if Role.Value = "dab" then -- Checks if the role value is "dab" Player.TeamColor = BrickColor.new("Bright red") -- If it is, this will change their team. wait() -- Waits Player:LoadCharacter() -- This will load their character after, and make them respawn/ end -- Ending the if statement for "Role.Value" end) -- Ends the event of someone joining the game.
Please put your code in a code block by clicking the "Lua" icon on top of the question box. This will generate a bunch of tildes (~) for you to paste your code in between the tildes.
Now, to answer your question.
There is a lot wrong with the code, player
is undefined, and you have a syntax error
in your if statement. The 'equal to' operator is ==
, the assignment operator is =
. Additionally, the onPlayerEntered
function is nested in your if statement, which is what you don't want. You also never parented the StringValue to anywhere neither did you use it for anything other than to assign the Value
property to the player's role.
local function onPlayerEntered(player) local role = player:GetRoleInGroup(4539848) if role == "dab" then player.TeamColor = BrickColor.new("Bright red") end end game:GetService("Players").PlayerAdded:Connect(onPlayerEntered)
And there you have it! The code should work as expected.