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

please help me fix this script?

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

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.

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