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

How do I do a Check?

How do I set this giver so that if someone already has this tool in their starter pack it will not give them another?

local Part = script.Parent --Part to get touched
local Tool = game.ReplicatedStorage["OCA Nano"] --The tool you want to give them
local TeamColor = "Bright blue" --Team color here

Part.Touched:connect(function(hit)
    local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
    if Player and Player.TeamColor == BrickColor.new(TeamColor) then
        Tool:Clone().Parent = Player.Backpack
        Tool:Clone().Parent = Player.StarterGear
    end
end)

1 answer

✓ Accepted answer

In your if statement you can look to see if the tool is in the backpack or the StarterGearby doing this:

if not Player.Backpack:FindFirstChild("OCA Nano") and not Player.StarterGear:FindFirstChild("OCA Nano") then

I used and not which means if that statement is false(In this case it would mean if it's not in the backpack or startergear). I also used FindFirstChild which looks for a child in Startergear and the backpack. So that's how you do a quick check. Just check if the tool is in BackPack or startergear

Your final code should look like this.

local Part = script.Parent --Part to get touched
local Tool = game.ReplicatedStorage["OCA Nano"] --The tool you want to give them
local TeamColor = "Bright blue" --Team color here

Part.Touched:connect(function(hit)
    local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
    if Player and Player.TeamColor == BrickColor.new(TeamColor) and  not Player.Backpack:FindFirstChild("OCA Nano") and not Player.StarterGear:FindFirstChild("OCA Nano") then
        Tool:Clone().Parent = Player.Backpack
        Tool:Clone().Parent = Player.StarterGear
    end
end)


5 comments

0

It says "unknown global player"

0

Woops, capitalize the 'p' in the player. I updated my post The code is fully functional now

0

Thanks works great!

0

Glad I could help!

0

I would like to give a more technical definition of 'not'. 'not' reverses a boolean. It works like this; If FindFirstChild returns nil (nil = false) then the 'not' reverses that boolean, changing it to true, allowing the if statement to pass.

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