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

Why isnt this magnitude script not working good enough?

I recently learned how to make it so parts can focus on a certain part or thing and i wanna do that with the player. I want the player's torso to rotate at where the part is when it gets near it but it isnt working correctly..

local Part = script.Parent

while wait() do
local Players = game:GetService('Players'):GetPlayers()
for i,v in pairs(Players) do
if v ~= nil and v.Character ~= nil then
local Torso = v.Character:FindFirstChild('Torso')
if Torso and (Torso.Position - Part.Position).Magnitude <= 10 then
Torso.CFrame = CFrame.new(Torso.Position, Torso.Position)
end
end
end
end

2 comments

0

How about next time you also learn how to indent?

0

We code in different ways, I like this way because nicer and much easier to read. Not like other idiots (You) that got out the border.

1 answer

✓ Accepted answer

Consider where you're pointing to

local Part = script.Parent

while wait() do
local Players = game:GetService('Players'):GetPlayers()
for i,v in pairs(Players) do
if v ~= nil and v.Character ~= nil then
local Torso = v.Character:FindFirstChild('Torso')
if Torso and (Torso.Position - Part.Position).Magnitude <= 10 then
Torso.CFrame = CFrame.new(Torso.Position, Part.Position) -- Be aware, this will screw the torso rotation. Roblox and players will disagree with this.
end
end
end
end

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