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

Is there a way to get the role of other players?

Asked by 3 years ago
Edited 3 years ago

Well i was trying to something like when you hover your mouse on a player it will show their role in the group

Here is the code:

local GroupID = 6326244 -- put your group id



local players = game:GetService("Players")
local plr = players.LocalPlayer
local playerGui = plr:WaitForChild("PlayerGui")
local mouse = plr:GetMouse()

local screenGui = Instance.new("ScreenGui", playerGui)
local mouseLabel = Instance.new("TextLabel", screenGui)
local rank = Instance.new("TextLabel", screenGui)

mouseLabel.BackgroundTransparency = 1
mouseLabel.Size = UDim2.new(0, 200, 0, 25)
mouseLabel.Font = Enum.Font.SourceSans
mouseLabel.Text = ""
mouseLabel.TextColor3 = Color3.fromRGB(255, 255, 255)
mouseLabel.TextStrokeTransparency = 0
mouseLabel.TextScaled = true
mouseLabel.Visible = false

if plr:IsInGroup(GroupID) then 
    rank.BackgroundTransparency = 1
    rank.Size = UDim2.new(0, 100, 0, 25)
    rank.Font = Enum.Font.SourceSans
    rank.Text = ""
    rank.TextColor3 = Color3.fromRGB(255, 255, 255)
    rank.TextStrokeTransparency = 0
    rank.TextScaled = true
    rank.Visible = false

local function onMouseMove()
    local target = mouse.Target
    if target ~= nil then
        if players:GetPlayerFromCharacter(target.Parent) then
            mouseLabel.Text = target.Parent.Name
            mouseLabel.Position = UDim2.new(0, mouse.X, 0, mouse.Y)
            mouseLabel.Visible = true
            rank.Text = target.Parent:GetRoleInGroup(GroupID)
            rank.Position = UDim2.new(0, mouse.X, 0, mouse.Y)
            rank.Visible = true
        else
            mouseLabel.Visible = false
            rank.Visible = false
        end
    else
        mouseLabel.Visible = false
        rank.Visible = false
    end
    end
    mouse.Move:connect(onMouseMove)
end

0
The function was never called upon, therefore, the binding instruction of your `onMouseMove` callback to the Move signal of Mouse will never be executed. Calling the function isn't the go-to fix either, you'll recurse. Your best option is to move like 52 outside of the scope. Ziffixture 6913 — 3y
0
Your logic is backwards, you should not have the function inside the if statement, you should have the if statement inside the function, then from outside, you can call mous.Move:Connect(onMouseMove). Also, case matters, so capitalize those C's in Connect. SteamG00B 1633 — 3y

Answer this question