I made a script that, if you touch a part and you have enough wins, it gives you a tool but only if it’s not already in you backpack or humanoid (when equipped) but still gives an extra item when equipped
here’s my script:
local SS = game:GetService("ServerStorage")
local Wins = 1
local Item = "ClassicSword"
local Debounce = true
script.Parent.Touched:Connect(function(Hit)
local humanoid = Hit.Parent:FindFirstChild("Humanoid")
if humanoid then
local Player = game:GetService("Players"):GetPlayerFromCharacter(Hit.Parent)
if Player and Debounce == true then
if Player.leaderstats.Wins.Value >= Wins then
if not Player.Backpack:FindFirstChild(Item) or humanoid:FindFirstChild(Item) then
Debounce = false
local Item = SS[Item]:Clone()
Item.Parent = Player:WaitForChild("Backpack")
wait(1)
Debounce = true
end
end
end
end
end)
slight mistake: when tools are equipped, they are put in the players character, not in the players humanoid. add that to your if statement and it may fix your problem.
That’s very true, thanks a lot! I also forgot to use “and” instead of “or”. As well as a “not” after the “and” to put a not to signify that the tool is not in the player.
Here’s the final code if anyone has the same issue in the future:
local SS = game:GetService("ServerStorage")
local Wins = 1
local Item = "ClassicSword"
local Debounce = true
script.Parent.Touched:Connect(function(Hit)
local humanoid = Hit.Parent:FindFirstChild("Humanoid")
if humanoid then
local Player = game:GetService("Players"):GetPlayerFromCharacter(Hit.Parent)
if Player and Debounce == true then
if Player.leaderstats.Wins.Value >= Wins then
if not Player.Backpack:FindFirstChild(Item) and not humanoid.Parent:FindFirstChild(Item) then
Debounce = false
local Item = SS[Item]:Clone()
Item.Parent = Player:WaitForChild("Backpack")
wait(1)
Debounce = true
end
end
end
end
end)