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

How do you determine a player's team by hovering your mouse over them?

Asked by
nilVector 812 Moderation Voter
9 years ago

I'm trying to make it to where when you hover over a player, if he/she is part of a specific team, it'll show a specific GUI on him/her, but I keep getting an error saying, "TeamColor is not a valid member of Workspace" in the Developer's Console. Here's the script (it's a LocalScript inside the GUI I want to appear if the person is part of the team):

local sp = script.Parent
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local teamColor = BrickColor.new("White")

while wait() do
    if mouse.Target then
        if mouse.Target.Parent:FindFirstChild("Humanoid") then
            if mouse.Target.Parent.Parent.TeamColor == teamColor then
                sp.Visible = true
            else
                sp.Visible = false
            end
        elseif mouse.Target.Parent.Parent:FindFirstChild("Humanoid") then
            if mouse.Target.Parent.Parent.Parent.TeamColor == teamColor then
                sp.Visible = true
            else
                sp.Visible = false
            end
        else
            sp.Visible = false
        end
    end
end

1 answer

Log in to vote
2
Answered by
2eggnog 981 Moderation Voter
9 years ago

The parent of a player's character is the Workspace, not the player.

local sp = script.Parent
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local teamColor = BrickColor.new("White")

while wait(.1) do
    if mouse.Target then
        if game.Players:GetPlayerFromCharacter(mouse.Target.Parent) then
            if game.Players[mouse.Target.Parent.Name].TeamColor == teamColor then
                sp.Visible = true
            else
                sp.Visible = false
            end
        elseif game.Players:GetPlayerFromCharacter(mouse.Target.Parent.Parent) then
            if game.Players[mouse.Target.Parent.Parent.Name].TeamColor == teamColor then
                sp.Visible = true
            else
                sp.Visible = false
            end
        else
            sp.Visible = false
        end
    end
end
0
Also, you don't really need to check 30 times a second. Checking every 0.5 seconds should be quick enough for your needs. Perci1 4988 — 9y
0
I'd argue that half a second is too slow. Personally, I'd go with 1/10th of a second. 2eggnog 981 — 9y
0
Thank you very much! +1'd your Reputation! nilVector 812 — 9y
Ad

Answer this question