wait(2) local player = game.Players.LocalPlayer local char = player.Character local mouse = player:GetMouse() local mouseCFrame = mouse.Hit local mousePos = mouseCFrame.p local tool = game.StarterPack.Tp_Move local UIS = game:GetService("UserInputService") local dfuser = true local human = char:WaitForChild("Humanoid") local HumanRoot = char:FindFirstChild("HumanoidRootPart") function TP (inputObject, gameProcessedEvent,mouse) if inputObject.KeyCode == Enum.KeyCode.Q and dfuser == true then dfuser = false HumanRoot.CFrame = CFrame.new(mousePos) end print("q",mousePos) wait(0.15) dfuser = true end UIS.InputBegan:Connect(TP,print(mousePos))
I need help it works in the start but it teleports me where the mouse was when we joined the game
Thats because you set the mousePos when the game started, you need to get rid of the mousePos variable and just have it inside the key event:
wait(2) local player = game.Players.LocalPlayer local char = player.Character local tool = game.StarterPack.Tp_Move local dfuser = true local human = char:WaitForChild("Humanoid") local HumanRoot = char:FindFirstChild("HumanoidRootPart") local uis = game:GetService("UserInputService") uis.InputBegan:Connect(function(Input, IsTyping) if Input.KeyCode == Enum.KeyCode.Q and not IsTyping and and dfuser == true then dfuser = false HumanRoot.CFrame = CFrame.new(mouse.Hit.p) end print("q",mousePos) wait(0.15) dfuser = true end end)
If this answers your question, then please mark it as the accepted answer.