So basically I want to make Time Magic when you press the Q key, and then you teleport where you cursor is. I already have the Key part, but how can I make it so that you teleport where your cursor is.
This local script is in StarterCharacterScripts btw. I only have the Key part so far.
Using :GetMouse()
in a Local Script, you can get the Player's Mouse. In this instance, we can use Mouse.Hit
and Mouse.Target
. Mouse.Hit
returns the CFrame of the Cursor. In simpler terms, where the Mouse is pointing. Mouse.Target
returns the object the object the Mouse is pointing to. In this instance, we want to use Mouse.Hit
to get the CFrame of the Mouse. When we do that, we can set our HumanoidRootPart's CFrame to the CFrame of the Mouse. It would look something like this.
local Player = game.Players.LocalPlayer -- The Player local Character = Player.Character or Player.CharacterAdded:Wait() -- The Character local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart") -- This is what we will use to teleport the Player local UserInputService = game:GetService("UserInputService") local Mouse = Player:GetMouse() -- Getting the Player's Mouse. UserInputService.InputBegan:Connect(function(input, gameProcessed) if gameProcessed then return end -- If they are typing in chat then do nothing. if input.KeyCode == Enum.KeyCode.Q and Mouse.Hit then -- If Mouse.Hit exists and Player presses Q then. We also added that to check if the Player's Cursor is pointing to the sky which would return nil for obvious reasons. local MouseCFrame = Mouse.Hit --Setting a Variable to the Mouse's CFrame (Optional). HumanoidRootPart.CFrame = MouseCFrame -- Set the HumanoidRootPart's CFrame to the Mouse's CFrame meaning teleport the Player to the Mouse. end end)