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

how do i get the mouses position via script?

im trying to make a block move to my mouses position everytime i tap f but it keeps moving to where i spawned heres my script

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local mp = mouse.Target.Position
local m = game.Players.LocalPlayer:GetMouse()
db = true
m.KeyDown:connect(function(k)
	k = k:lower()
	if k == "f" then
		if db == true then
			game.Workspace.Part.Position = mp 
			db = false
			wait(3)
			db = true
		end
	end
end)

2 comments

0

OOF! use code block

0

?? whats that

2 answers

✓ Accepted answer
UIS = game:GetService("UserInputService")
local player = game.Players.LocalPlayer 
local mouse = player:GetMouse()
db = true

UIS.InputBegan:Connect(function(k, process)
    if k.KeyCode == Enum.KeyCode.F then
        if db == true then
            game.Workspace.Part.Position = mouse.Hit.Position 
            db = false
            wait(3)
            db = true
        end
    end
end)

3 comments

0

Hey you copied my script :(

0

lol

0

thx it worked

This is not an answer We just can't see the code

local player = game.Players.LocalPlayer 
local mouse = player:GetMouse() 
local mp = mouse.Target.Position
local m = game.Players.LocalPlayer:GetMouse() 
db = true 
m.KeyDown:connect(function(k) 
	k = k:lower() 
	if k == "f" then 
		if db == true then 
			game.Workspace.Part.Position = mp 
			db = false 
			wait(3) 
			db = true 
		end 
	end 
end)

That's ur code and I don't recommend KeyDown because it is deprecated. Youtube can be a good source for scripting but some scripts are bad. UserInputService is a pretty good one. I'll show u.

UIS = game:GetService("UserInputService") local player = game.Players.LocalPlayer mouse = player:GetMouse() local mp = mouse.Hit.Position --we use hit.Position not Target.Position db = true

UIS.InputBegan:Connect(function(k, process)--k is what the person pressed if k.KeyCode == Enum.KeyCode.F then if db == true then game.Workspace.Part.Position = mp db = false wait(3) db = true end end end)

not 100% sure the script works because I'm not good with CFrame but I'm positive that we use mouse.Hit.p

5 comments

0

thx it helped a lot

0

wait sorry

0

i ran into a problem it only teleports to a fixed location

0

idk if this will help but im using a local script in starterplayerscripts

0

try starterpack

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