local sword = game.Lighting.LinkedSword local ClickDetector = Instance.new("ClickDetector") ClickDetector.Parent = script.Parent ClickDetector.MouseClick:connect(function(player) if not player.Backpack:FindFirstChild(sword.Name) and not (player.Character and player.Character:FindFirstChild(sword.Name)) then sword:Clone().Parent = player.Backpack end end)
Its supposed to give the first person who clicks it the item "LinkedSword" from lighting, then it disables the brick so it doesnt give it to anyone else, then it checks the game to see if someone has it in their backpack, if no one has it in their backpack it enables the brick again for the other person. I mean it sort of works, but when I click it, it gives me the tool, and wont let me click it again, but it will give other players the tools even if someone has the item in their backpack. Can someone fix it so only one person gets the item then it disables the brick so no one else can get it but then if the player loses the item or does not have it, it enables itself again? I wanted to use boolean but wasn't sure how, thanks!
local sword = game.Lighting.LinkedSword local ClickDetector = Instance.new("ClickDetector") ClickDetector.Parent = script.Parent ClickDetector.MouseClick:connect(function(player) for i,v in pairs(game.Players:GetPlayers()) do --Loops through all players if v.Backpack:findFirstChild(sword.Name) or --If the current player has it, then v.Character:findFirstChild(sword.Name) then return --Stop the function end end sword:Clone().Parent = player.Backpack --Imaginary elseif, gives the player the tool if the function did not return. end)
I think you put a parenthesis by accident on (player.Character and
I am not the best scripter, it may need to go there, it may not.
local sword = game.Lighting.LinkedSword local ClickDetector = Instance.new("ClickDetector") ClickDetector.Parent = script.Parent ClickDetector.MouseClick:connect(function(player) if not player.Backpack:FindFirstChild(sword.Name) and not player.Character and player.Character:FindFirstChild(sword.Name)) then sword:Clone().Parent = player.Backpack end end)