Help with team only script!

Hey i was making an game with my friends and i tried to make a team only script.
it didnt work,i was trying to make an Team only billboard giver. i would be very happy if you guys could help me.

function onTouched(hit)
local human = hit.Parent:FindFirstChild("Head") 

if (human ~= nil) then 

game.Lighting.BillboardGui:Clone().Parent = human

end

end

if (script.Parent ~= nil) and (script.Parent.className == “Part”) then
connection = script.Parent.Touched:connect(onTouched)
end

There is a property of the player instance called team, it’s an object value that correlates to the designated team. You can check by doing;

if player.Team == teaminstance then
   -- code here
end
1 Like

Checking for a humanoid is outdated method I would say, and unreliable as anything can have a humanoid in it. Even non-player characters!

The canonical way to verify if a player touched is via Players:GetPlayerFromCharacter.

local Players = game:GetService("Players")
local team = game:GetService("Teams").Team -- your team

script.Parent.Touched:Connect(function(part)
    local player = Players:GetPlayerFromCharacter(part.Parent) -- if part.Parent is a player character
    if player then -- if it's not nil...
        if player.Team == team then
            -- Clone the BillboardGui from SERVER STORAGE or REPLICATED STORAGE :)
        end
    end
end)

Also, don’t use Lighting for storage. Use ServerStorage and ReplicatedStorage. That is what they are meant for. Storing. There is no reason to store things in Lighting (other than skyboxes and post-processing effects) anymore.

1 Like

i will try this thank you for the help

if the other one dont work gonna try this one too thx :slight_smile: