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

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

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

✓ Accepted answer

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)

2 comments

1

It worked, thanks!

0

I am happy to help

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