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

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

Asked by 6 years ago
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)


0
I believe KeyDown is deprecated. Use UserInputService instead ABK2017 406 — 6y
0
^ lunatic5 409 — 6y
0
it wont work helleric -3 — 6y
0
if mouse then <-- use this, easy and simple fix greatneil80 2647 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

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)
0
This is wrong. CFrame.p is deprecated, it is CFrame.Position now. OP was correct. User#19524 175 — 6y
0
Oh damn! You learn something new every day! boatbomber 27 — 6y
Ad

Answer this question