Well im developing a game about swordfighting, im building a practice zone in the lobby. The system is basically a part that gives it when touching it and a part that removes it. The problem is that when the player does a jump and exits the zone it doesnt remove the sword from him or even sometimes the script gives him two swords and when he exits the zone it just deletes one of the swords. This bug only works when the player exits the zone with a jump and i really dont know how to solve it.
Here is the script
if v.Name == "ArenaLeave" then
v.Touched:connect(function(Leave)
if Leave.Parent:FindFirstChild("Humanoid") then
local plr = game.Players:GetPlayerFromCharacter(Leave.Parent)
local bp = plr.Backpack
if bp:FindFirstChild("ClassicSword") ~= nil then
bp.ClassicSword:Remove()
end
if Leave.Parent:FindFirstChild("LinkedSword") ~= nil then
Leave.Parent.ClassicSword:Remove()
end
end
end)
end
end
That is specifically the script for removing the sword.
Touched events are notoriously buggy so I would recommend not using them. Instead, create a flat zone out of part(s) that you want to represent your zone. You can then raycast downwards from the character’s HumanoidRootPart with a whitelist of the folder that holds those zone parts.
I see a few issues in your script you are only checking the backpack for classic sword one time and also only checking the character 1 time which I am guessing is Leave.Parent
Also you are using :Remove() this has been deprecated for a very long time its what we used to use back in the 07-12 days so you shouldn’t use that anymore instead use :Destroy()
below is your script fixed to loop through the backback and check for either sword and remove it and also through the character which is where the tool/sword maybe if it is equipped
if v.Name == "ArenaLeave" then
v.Touched:connect(function(Leave)
if Leave.Parent:FindFirstChild("Humanoid") then
local Character = Leave.Parent -- set a variable for the character..
local plr = game.Players:GetPlayerFromCharacter(Character)
local bp = plr.Backpack
for _, tool in ipairs(Character:GetChildren()) do -- check through the character's children for either sword and remove if found
if tool.Name == 'ClassicSword' or tool.Name == 'LinkedSword' then
tool:Destroy()
end
end
for _, tool in ipairs(bp:GetChildren()) do -- go through all children in backpack if either has the name of the swords remove them
if tool.Name == 'ClassicSword' or tool.Name == 'LinkedSword' then
tool:Destroy()
end
end
end
end)
end