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

Trying to make a TextLabel's text the LocalPlayer's Rank in the group. Isn't working?

Asked by
ghxstlvty 133
4 years ago
Edited 4 years ago
local groupid = 6693950
local text1 = script.Parent

game.Players.PlayerAdded:Connect(function(plr)
    text1.Text = (plr:GetRoleInGroup(groupid))
end)

Script is a LocalScript

1 answer

Log in to vote
1
Answered by
rabbi99 714 Moderation Voter
4 years ago

You can't do game.Players.PlayerAdded in localscripts. I suggest you making a RemoteEvent and call it "PlayerGroup" and put it in ReplicatedStorage.

Here is the the script you need to make in ServerScriptService:

rp = game:GetService("ReplicatedStorage")
playergroup = rp:WaitForChild("PlayerGroup")


game.Players.PlayerAdded:Connect(function(plr)
    local roleplr = plr:GetRoleInGroup(3336691)
    print(plr, "is", roleplr) -- This is useful for testing
    playergroup:FireAllClients(plr, roleplr)
end)

And this your localscript:

local text1 = script.Parent
local rp = game:GetService("ReplicatedStorage")
local playergroup = rp:WaitForChild("PlayerGroup")
player = game.Players.LocalPlayer


playergroup.OnClientEvent:connect(function(plr, rank)
    if plr ~= nil and plr.Name == player.Name then
        text1.Text = rank
    end
end)
1
It worked, thanks! ghxstlvty 133 — 4y
0
I am happy to help rabbi99 714 — 4y
Ad

Answer this question