Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why doesn't The "Tool" destroy when player position is greater than the Magnitude?

Asked by 2 years ago
local Part = workspace.PvP.PvPZ
local Tool = game.Lighting.Storage:WaitForChild("LinkedSword")

while true do
    for _, Player in pairs(game.Players:GetPlayers()) do
        local Character = Player.Character
        if Character and Player.Backpack:FindFirstChild("LinkedSword") == nil and Character:FindFirstChild("LinkedSword") == nil then
            if (Character.HumanoidRootPart.Position - Part.Position).Magnitude < 30 then
                local Clone = Tool:Clone()
                Clone.Parent = Player.Backpack
                if (Character.HumanoidRootPart.Position - Part.Position).Magnitude > 30 and Player.Backpack:FindFirstChild("LinkedSword") then
                    Player.Backpack.LinkedSword:Destroy()
                else
                    if Character:FindFirstChild("LinkedSword") then
                        Character.LinkedSword:Destroy()
                        end
                end
            end
        end
    end
    wait(0.001)
end

I know this is a mess, Im not too good at scripting.

Answer this question