When a player enters this area he gets a sword, and when he leaves it removed the sword from players Backpack, but not the player's character, HELP!
local ToolNames = {"Sword"}
local part = script.Parent
local Debounces = {}
local Storage = game:GetService("ServerStorage")
function RemoveWeapons(parent)
local weapons = parent:GetChildren()
for i = 1,#weapons do
for _, v in pairs(ToolNames) do
if (weapons[i].className == "Tool") and (weapons[i].name == v) then
weapons[i]:Destroy()
end
end
end
end
local function onTouch(part)
Player = game.Players:GetPlayerFromCharacter(part.Parent)
if Player and not Debounces[Player.UserId] then
Debounces[Player.UserId] = true
Backpack = Player:WaitForChild("Backpack")
for i = 1, #ToolNames do
local Tool = Storage:FindFirstChild(ToolNames[i])
if Tool then
Tool:clone().Parent = Backpack
end
end
end
end
local function onTouchEnded(part)
if Player and Debounces[Player.UserId] then
if (table.maxn(Backpack:GetChildren()) > 0) then
RemoveWeapons(Backpack)
RemoveWeapons(Player.Character) <----- Error Error here
Debounces[Player.UserId] = false
end
end
end
part.Touched:Connect(onTouch)
part.TouchEnded:Connect(onTouchEnded)

1 comment
What is this? did you even read my script? or just answer based on the title