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

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

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

✓ Accepted answer

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

3 comments

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.

0

I'd argue that half a second is too slow. Personally, I'd go with 1/10th of a second.

0

Thank you very much! +1'd your Reputation!

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