I don't Know what do to with Mouse position so I left the Position checker
if Mouse.Position > 500 then end
.
-- Variables -- local replicated = game:GetService("ReplicatedStorage") local player = game:GetService("Players").LocalPlayer local Remote = game.ReplicatedStorage.RemoteEvents:WaitForChild("Lightning") local UserInputService = game:GetService("UserInputService") local humanoid = player.Character:WaitForChild("Humanoid") Mouse = player:GetMouse() Debounce = true wait(1) UserInputService.InputBegan:Connect(function(input, gameProcessed) if gameProcessed then return end if input.UserInputType == Enum.UserInputType.MouseButton1 then if Mouse.Position > 500 then end else player.Character:MoveTo(Mouse.Hit.p) end end)
The answer is quite simple; using the magnitude properties of a Vector3 you can calculate the distance between two positions:
local distance = (part1.Position - part2.Position).magnitude
Here's your script with the extra snippet of code:
-- Variables -- local replicated = game:GetService("ReplicatedStorage") local player = game:GetService("Players").LocalPlayer local Remote = game.ReplicatedStorage.RemoteEvents:WaitForChild("Lightning") local UserInputService = game:GetService("UserInputService") local humanoid = player.Character:WaitForChild("Humanoid") Mouse = player:GetMouse() Debounce = true wait(1) UserInputService.InputBegan:Connect(function(input, gameProcessed) if gameProcessed then return end if input.UserInputType == Enum.UserInputType.MouseButton1 then if (Mouse.Hit.p - humanoid.Parent.HumanoidRootPart.Position).magnitude > 500 then end else player.Character:MoveTo(Mouse.Hit.p) end end)
Hope this helps!