#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()
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
1 comment
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.