Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to get the position of the mouse when Q is pressed?

Asked by 6 years ago
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

0
i dont think u can print mouse position tacotown2 119 — 6y
0
you set the variables in the beginning, they won't change unless you change them. I'm typing up an answer right now. SteamG00B 1633 — 6y
0
also taco, you can print anything. SteamG00B 1633 — 6y

1 answer

Log in to vote
0
Answered by
SteamG00B 1633 Moderation Voter
6 years ago
Edited 6 years ago

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.

0
thx it helped alot NathanGaming2005 2 — 6y
0
hey if i want to put it in a tool how'd do i do that NathanGaming2005 2 — 6y
0
You could probably have this script disabled by default while inside the character scripts, and then when you equip a tool, all the script inside the tool would do is enable this script when you equip the tool and disable it when it is dequipped. SteamG00B 1633 — 6y
0
ok NathanGaming2005 2 — 6y
Ad

Answer this question