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

Ok so i want to make that only player that have "dab" rank in group can spawn here ?

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

4 comments

0

fix lua tags

0

This question is super vague, I would need more information to answer it to the best of my ability. Check this out for future questions and answers: https://scriptinghelpers.org/blog/posting-good-questions-and-answers-on-scripting-helpers.

0

Please do not forget to hit "Accept Answer" if my answer helped you out,

0

I fixed the indentation and put the code in a code block.

2 answers

✓ Accepted answer

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.

6 comments

0

-1. Too many comments, makes it very hard to read. OP knew what the if statements, and what :LoadCharacter() and all that did. why re explain what OP already knew?

0

I see no problem explaining something that someone already knew. And the text thing is HTML not me. I was just trying to explain sorry if I hurt your feelings.

0

lol and you will unjustly downvote me 4 that? jesus christ

0

Comments aren't needed - StringValue isn't need for checking - the wait()s aren't needed

0

Who cares.

0

It worked. That's all that matters.

For future reference

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.

Answer

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.

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