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)
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.
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