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

Does this point and click look good?

Asked by
palpc 0
9 years ago
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.

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. Perci1 4988 — 9y

1 answer

Log in to vote
2
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
9 years ago

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.

Ad

Answer this question