Answered by
4 years ago Edited 4 years ago
First you'd need the mouse's position on the workspace. We also need the Character of this player to get to the Humanoid. The Humanoid holds the property WalkToPoint. This will be useful for the script that will manage this system you want. To get this information that script needs, we need to write this in a localscript. This localscript would be located in StarterPlayer > StarterPlayerScripts.
1 | local player = game.Players.Localplayer |
3 | local mouse = player:GetMouse() |
5 | mouse.Button 1 Up:Connect( function () |
6 | local ChosenPoint = mouse.Hit |
Then, we also want to send this information to a normal script. We're gonna put this script in ServerScriptService. To make this script receive this information we are also gonna make a RemoteEvent. We are gonna name this RemoteEvent "ClickToMove". ClickToMove needs to be located in ReplicatedStorage. But we'd also need to make the localscript send this information:
*The player
*The mouse its position in the workspace
*The character
To do that write this in the localscript:
01 | local rp = game:GetService( "ReplicatedStorage" ) |
02 | local ClickToMove = rp:WaitForChild( "ClickToMove" ) |
04 | local player = game.Players.Localplayer |
05 | local mouse = player:GetMouse() |
07 | mouse.Button 1 Up:Connect( function () |
08 | local ChosenPoint = mouse.Hit |
09 | ClickToMove.FireServer(ChosenPoint) |
Great, now we've sent this information! But now we need to make the script located in the ServerScriptService to receive and process this information.
First we want it to collect it of course:
1 | local rp = game:GetService( "ReplicatedStorage" ) |
2 | local ClickToMove = rp:WaitForChild( "ClickToMove" ) |
4 | ClickToMove.OnServerEvent:Connect( function (player, ChosenPoint, character) |
Nice! Now we have collected the information from the localscript. Now we can finally process this information in the script that's located in the ServerScriptService
01 | local rp = game:GetService( "ReplicatedStorage" ) |
02 | local ClickToMove = rp:WaitForChild( "ClickToMove" ) |
04 | ClickToMove.OnServerEvent:Connect( function (player, ChosenPoint, character) |
05 | local character = player.Character |
07 | local PointY = character.HumanoidRootPart.Position.Y |
08 | local PointX = ChosenPoint.X |
09 | local PointZ = ChosenPoint.Z |
10 | character.Humanoid.WalkToPoint = Vector 3. new(PointX, PointY, PointZ) |
That's it! I hope you liked my tutorial!