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

Does this point and click look good?

local m = game.Players.LocalPlayer:GetMouse()
m.Button1Down:connect(function() onButton1Down(m) end)
function onButton1Down(m)
if m.Hit == nil then return end
if m.Hit.p == nil then return end
if m.Target == nil then return end
if m.Target.Parent == nil then return end
local Hit = m.Hit.p
local Target = m.Target
if ((((Hit) - (game.Players.LocalPlayer.Character:findFirstChild("Torso").Position)).magnitude)<=50) then
game.Players.LocalPlayer.Character:findFirstChild("Humanoid"):MoveTo(Hit,Target)
end
end

It's been glitching a bit.

1 comment

0

Well, you do a lot of unnecessary checks and you have A LOT of parentheses on line 10 that I don't think you need.

1 answer

You have unnecessary checks:

Hit is a CFrame value and will not be nil.

The p property of a CFrame and as a property of a valid object will never be nil.

Because you are mousing over mouse.Target, its parent cannot be nil either.


Using FindFirstChild as you do in lines 10 and 11 is pointless. It only makes it safer when you do error checking on the result, e.g.

-- an example
if character:FindFirstChild("Torso") then
	character.Torso:Destroy()
end

However,

character:FindFirstChild("Torso"):Destroy()

is just a long winded way of writing

character.Torso:Destroy()

Otherwise, this should work, except that using this to move the Player's character most likely will not have consistent effects since the player's default controls will also be moving them.

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