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

please help me fix this script?

Asked by
mehssi 20
8 years ago
local color = BrickColor.new("Bright red")
script.Parent.Touched:connect(function(hit)
    local p = game.Players:GetPlayerFromCharacter(hit.Parent)
    if p then
        if p.TeamColor == color then
    game.Lighting.GK:Clone().Parent = p.Backpack
            end
        end
end)

this gives the player the tool but if he keeps standing on it, he will keep getting the tool can someone help me make the player only get the tool if he doesn't have it already PLEASE!!

1 answer

Log in to vote
0
Answered by
1waffle1 2908 Trusted Badge of Merit Moderation Voter Community Moderator
8 years ago

Make it check if the player already has the tool.

local color = BrickColor.new("Bright red")
local tool = "GK"
script.Parent.Touched:connect(function(hit)
    local p = game.Players:GetPlayerFromCharacter(hit.Parent)
    if p and p.TeamColor == color and not p.Backpack:FindFirstChild(tool)and not hit.Parent:FindFirstChild(tool)then
        game.Lighting[tool]:Clone().Parent = p.Backpack
    end
end)

I also recommend not using Lighting to store objects.

Ad

Answer this question