Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

My magnitude script is wrong?

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

✓ Accepted answer

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

This discussion is preserved as it was. New answers, comments, and votes are closed.