Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

3 comments

0

i dont think u can print mouse position

0

you set the variables in the beginning, they won't change unless you change them. I'm typing up an answer right now.

0

also taco, you can print anything.

1 answer

✓ Accepted answer

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.

4 comments

0

thx it helped alot

0

hey if i want to put it in a tool how'd do i do that

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.

0

ok

This discussion is preserved as it was. New answers, comments, and votes are closed.