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

My magnitude script is wrong?

Asked by
Nidoxs 190
8 years ago

Hello, I know that I'm close to solving magnitude but I don't understand how to fix this (If player is within 10 studs of brick in Workspace, kill them.):

local a = game.Workspace.P1

game.Players.ChildAdded:connect(function(Player)
    if Player then
        if game.Workspace:FindFirstChild(Player.Name) then
            local Char = Player.Character
            local Tors = Char:WaitForChild("Torso")
            while true do
                if (a.Position - Tors.Position).magnitude < 10 then
                    Char:BreakJoints()
                    wait(.01)
                end
                wait(.01)
            end
        end
    end
end)

1 answer

Log in to vote
0
Answered by 8 years ago

I can't tell any problems with your magnitude check, but there are some other pieces you may want to de-ew that may work on. Here I'm going to wait until the character exists, and actually take damage on the player.

local a = game.Workspace.P1

game.Players.ChildAdded:connect(function(Player)
    if Player then
        repeat wait() until game.Workspace:FindFirstChild(Player.Name) 
            local Char = Player.Character
            local Tors = Char:WaitForChild("Torso")
            while wait() do
                if (a.Position - Tors.Position).magnitude < 10 then
                    Char.Humanoid:TakeDamage(Char.Humanoid.Health)

                end
                wait()
            end
        end
    end
end)


If this helped, make sure to accept and upvote!

~Chem

Ad

Answer this question