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

How do you find how many of the same objects you have in the players character?

Asked by
FiredDusk 1466 Moderation Voter
8 years ago

I am trying to do, if the player's character has 2 or more objects named "SpikeHair" then it does certain code.

--More code up here
if Player.Character.SpikeHair == #2 then
        --Code here
    end

1 answer

Log in to vote
1
Answered by 8 years ago

local num = 0 -- makes a global variable for i,v in pairs(Player.Character:GetChildren()) do -- iterates thruout character if v.Name = "SpikeHair" then -- makes a condition if the name is SpikeHari num = num+1 -- counts it end end if num >= 2 then -- if the hair is more than 2 --code here end
Ad

Answer this question