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

WalkToPoint's Position not working?

Asked by
RoyMer 301 Moderation Voter
8 years ago

For some reason this script is taking me to position (0,0,0) rather than the position of the bricks. (The Bricks are named Step and a number Ex: Step1)

local player = game.Players.LocalPlayer

function Click()

player.PlayerGui.RandomNumber.Value = (math.random(1,5)) 
local RandomNumber = player.PlayerGui.RandomNumber.Value
print("Random number: "..RandomNumber)

local name = "Step"..RandomNumber
print("Name: "..name)

local position = Vector3.new(game.Workspace:FindFirstChild(name).Position)

player.Character.Humanoid.WalkToPoint = Vector3.new(position)
end

script.Parent.MouseButton1Down:connect(Click)

0
You're wrapping a Vector3 inside a Vector3. Just do "position = game.Workspace:FindFirstChild(name).Position" (without quotes). Also, keep in mind that a variable will not update to the property's new value if you set it as a property of an object. Spongocardo 1991 — 8y

1 answer

Log in to vote
0
Answered by 8 years ago

This may not be the problem, but it is a solution.

local player = game.Players.LocalPlayer


function Click() player.PlayerGui.RandomNumber.Value = (math.random(1,5)) local RandomNumber = player.PlayerGui.RandomNumber.Value print("Random number: "..RandomNumber) local name = "Step"..RandomNumber print("Name: "..name) local position = Vector3.new(game.Workspace:FindFirstChild(name).Position) player.Character.Humanoid:MoveTo(position) end script.Parent.MouseButton1Down:connect(Click)

Ok, let me explain.

You were using 2 Vector3.new's. One for position, and one for WalkToPoint.

This isn't right, but as you can see, it isn't wrong either.

But instead of just telling you to remove the Vector3.new, I'm going to introduce you to a new thing, a function of the humanoid. It's name?

  MoveTo()
  

Have you ever heard of it before? Most people I've seen stopped using WalkToPoint or MoveToPoint and started using this. I can understand why. It's shorter, and doesn't take much. But that's just a minuscule difference.

Oh, I forgot. there's another thing that comes with this package.

    `Humanoid.MoveToFinished:connect()

With this beautiful Event, it will tell you when MoveTo and only MoveTo is finished. We can do many things with like wait for the MoveTo to finish...

    `Humanoid.MoveToFinished:wait()`

Or even set an evil trap to force the NPC to walk to it, and make him explode!

Humanoid:MoveTo() -- Here we put our secret trap's location!
Humanoid.MoveToFinished:connect(function()
    instance.new("Explosion", Humanoid.Parent.Torso)
end)

So, with the edit I gave you, and the introduction of MoveTo, Go crazy, Even though it's a lot like WalkToPoint (and it's probably the same) We can still see the small differences.

Written with StackEdit. bai hungryjaffer

0
thanks it worked now! RoyMer 301 — 8y
Ad

Answer this question