local part = script.Parent
local givenSwords = {}
part.Touched:Connect(function(hit)
local char = hit.Parent
local humanoid = char and char:FindFirstChild(“Humanoid”)
if humanoid then
local plr = game.Players:GetPlayerFromCharacter(char)
if plr and not givenSwords[plr.UserId] then
givenSwords[plr.UserId] = true
local sword = game.ServerStorage:FindFirstChild(“ClassicSword”)
if sword then
sword:Clone().Parent = plr.Backpack
end
plr.CharacterRemoving:Connect(function()
givenSwords[plr.UserId] = nil
end)
end
end
end)
part.TouchEnded:Connect(function(hit)
local char = hit.Parent
local humanoid = char and char:FindFirstChild(“Humanoid”)
if humanoid then
local plr = game.Players:GetPlayerFromCharacter(char)
if plr then
local swordtool = plr.Backpack:FindFirstChild(“ClassicSword”) or plr.Character:FindFirstChild(“ClassicSword”)
if swordtool then
swordtool:Destroy()
givenSwords[plr.UserId] = nil
end
end
end
end)
this is the script inside the part ^ the problem is that on touchended, the sword wont destroy if plr got the sword equipped, instead it will remain in the inventory until plr will touchend the part again with sword unequipped, then, it will destroy
i would be glad if someone can help me