Basically, I found a script from a question about "Teleporting to the cursor when you press" that fitted what I was making. Heres what i copied.
local Player = game.Players.LocalPlayer local Character = Player.Character or Player.CharacterAdded:Wait() local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart") local UserInputService = game:GetService("UserInputService") local Mouse = Player:GetMouse() UserInputService.InputBegan:Connect(function(input, gameProcessed) if gameProcessed then return end if input.KeyCode == Enum.KeyCode.V and Mouse.Hit then local MouseCFrame = Mouse.Hit HumanoidRootPart.CFrame = MouseCFrame end end)
I put it in StarterPlayerScripts. I'm just wondering if there is a way to put a cooldown and/or specific range to this teleportation script?
You can distance check with magnitude, just subtract the two points to find the distance. You can implement a cool down by checking the last time you did something with tick().
local Player = game.Players.LocalPlayer local Character = Player.Character or Player.CharacterAdded:Wait() local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart") local UserInputService = game:GetService("UserInputService") local Mouse = Player:GetMouse() local LastTeleported = 1 local CoolDown = 1 local Reach = 30 UserInputService.InputBegan:Connect(function(input, gameProcessed) if gameProcessed then return end if input.KeyCode == Enum.KeyCode.V and Mouse.Target then local Pos = Mouse.Hit.p local Distance = (Pos - HumanoidRootPart.Position).magnitude if Distance <= Reach and tick() - LastTeleported >= CoolDown then LastTeleported = tick() Character:MoveTo ( Pos ) end end end)