Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 5 years ago
Edited by TheeDeathCaster 5 years ago
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
0
fix lua tags DinozCreates 1070 — 5y
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. NinjaManChase 226 — 5y
0
Please do not forget to hit "Accept Answer" if my answer helped you out, User#24403 69 — 5y
0
I fixed the indentation and put the code in a code block. TheeDeathCaster 2368 — 5y

2 answers

Log in to vote
-3
Answered by 5 years ago

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.
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? User#24403 69 — 5y
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. namespace25 594 — 5y
0
lol and you will unjustly downvote me 4 that? jesus christ User#24403 69 — 5y
0
Comments aren't needed - StringValue isn't need for checking - the wait()s aren't needed green271 635 — 5y
View all comments (2 more)
0
Who cares. namespace25 594 — 5y
0
It worked. That's all that matters. namespace25 594 — 5y
Ad
Log in to vote
1
Answered by 5 years ago

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.

Answer this question