I’m trying to make a part that if you stand on it it will give you a sword, but not more than one. I’ve tried checking for the sword in the player’s inventory, but it didn’t work. I currently have this:
local part = script.Parent
local repStore = game:GetService("ReplicatedStorage")
local sword = repStore:WaitForChild("ClassicSword")
part.Touched:Connect(function(hit)
local x=sword:Clone()
x.Parent = hit.Parent
end)
You can just check if the player already has the tool by using FindFirstChild
local part = script.Parent
local repStore = game:GetService("ReplicatedStorage")
local sword = repStore:WaitForChild("ClassicSword")
part.Touched:Connect(function(hit)
local Player = game:GetService('Players'):GetPlayerByCharacter(hit.Parent)
if Player and not Player.Character:FindFirstChild('ClassicSword') and not Player.Backpack:FindFirstChild('ClassicSword') then
local x=sword:Clone()
x.Parent = hit.Parent
end
end)