local down = true
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local we = false
mouse.KeyDown:Connect(function(key)
key = key:lower()
if key == "v" then
local e = Instance.new("Part",workspace)
e.Position = mouse.Hit.Position --here is error
end
end)
✓ ANSWER ACCEPTED
i have been getting mouse nill value how do i fix?
1 answer
✓ Accepted answer
First of all, you really should rewrite this to not use deprecated services.
However, I think your issue will be solved if you simply change mouse.Hit.Position to mouse.Hit.p
I've rewritten this using newer services for you!
--Warning: Untested code. I'm typing this into the answer box!
local UserInputService = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local function onInputBegan(input, gameProcessed)
if not gameProcessed and input.UserInputType == Enum.UserInputType.Keyboard then
if input.KeyCode == Enum.KeyCode.V then
local e = Instance.new("Part")
e.Position = mouse.Hit.p
e.Parent = workspace
end
end
end
UserInputService.InputBegan:Connect(onInputBegan)
2 comments
0
This is wrong. CFrame.p is deprecated, it is CFrame.Position now. OP was correct.
0
Oh damn! You learn something new every day!
This discussion is preserved as it was. New answers, comments, and votes are closed.

4 comments
I believe KeyDown is deprecated. Use UserInputService instead
^
it wont work
if mouse then <-- use this, easy and simple fix