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

How do I do a Check?

Asked by 9 years ago

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

Log in to vote
2
Answered by
Thetacah 712 Moderation Voter
9 years ago

In your if statement you can look to see if the tool is in the backpackor 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 Startergearand 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)


0
It says "unknown global player" MULTACxlr8 20 — 9y
0
Woops, capitalize the 'p' in the player. I updated my post The code is fully functional now Thetacah 712 — 9y
0
Thanks works great! MULTACxlr8 20 — 9y
0
Glad I could help! Thetacah 712 — 9y
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. Perci1 4988 — 9y
Ad

Answer this question