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

how do i get the mouses position via script?

Asked by 5 years ago
Edited 5 years ago

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)
0
OOF! use code block HappyTimIsHim 652 — 5y
0
?? whats that xxbrobroxx02 13 — 5y

2 answers

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago
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)
0
Hey you copied my script :( HappyTimIsHim 652 — 5y
0
lol xxbrobroxx02 13 — 5y
0
thx it worked xxbrobroxx02 13 — 5y
Ad
Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

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

0
thx it helped a lot xxbrobroxx02 13 — 5y
0
wait sorry HappyTimIsHim 652 — 5y
0
i ran into a problem it only teleports to a fixed location xxbrobroxx02 13 — 5y
0
idk if this will help but im using a local script in starterplayerscripts xxbrobroxx02 13 — 5y
0
try starterpack HappyTimIsHim 652 — 5y

Answer this question