I don't Know what do to with Mouse position so I left the Position checker
if Mouse.Position > 500 then end
.
01 | -- Variables -- |
02 | local replicated = game:GetService( "ReplicatedStorage" ) |
03 | local player = game:GetService( "Players" ).LocalPlayer |
04 | local Remote = game.ReplicatedStorage.RemoteEvents:WaitForChild( "Lightning" ) |
05 | local UserInputService = game:GetService( "UserInputService" ) |
06 | local humanoid = player.Character:WaitForChild( "Humanoid" ) |
07 |
08 | Mouse = player:GetMouse() |
09 | Debounce = true |
10 | wait( 1 ) |
11 |
12 | UserInputService.InputBegan:Connect( function (input, gameProcessed) |
13 | if gameProcessed then return end |
14 | if input.UserInputType = = Enum.UserInputType.MouseButton 1 then |
15 | if Mouse.Position > 500 then end |
16 | else |
17 | player.Character:MoveTo(Mouse.Hit.p) |
18 | end |
19 | end ) |
The answer is quite simple; using the magnitude properties of a Vector3 you can calculate the distance between two positions:
1 | local distance = (part 1. Position - part 2. Position).magnitude |
Here's your script with the extra snippet of code:
01 | -- Variables -- |
02 | local replicated = game:GetService( "ReplicatedStorage" ) |
03 | local player = game:GetService( "Players" ).LocalPlayer |
04 | local Remote = game.ReplicatedStorage.RemoteEvents:WaitForChild( "Lightning" ) |
05 | local UserInputService = game:GetService( "UserInputService" ) |
06 | local humanoid = player.Character:WaitForChild( "Humanoid" ) |
07 |
08 | Mouse = player:GetMouse() |
09 | Debounce = true |
10 | wait( 1 ) |
11 |
12 | UserInputService.InputBegan:Connect( function (input, gameProcessed) |
13 | if gameProcessed then return end |
14 | if input.UserInputType = = Enum.UserInputType.MouseButton 1 then |
15 | if (Mouse.Hit.p - humanoid.Parent.HumanoidRootPart.Position).magnitude > 500 then end |
16 | else |
17 | player.Character:MoveTo(Mouse.Hit.p) |
18 | end |
19 | end ) |
Hope this helps!