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

i have been getting mouse nill value how do i fix?

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)


4 comments

0

I believe KeyDown is deprecated. Use UserInputService instead

0

^

0

it wont work

0

if mouse then <-- use this, easy and simple 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.