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 5 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 — 5y
0
^ lunatic5 409 — 5y
0
it wont work helleric -3 — 5y
0
if mouse then <-- use this, easy and simple fix greatneil80 2647 — 5y

1 answer

Log in to vote
0
Answered by 5 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 — 5y
0
Oh damn! You learn something new every day! boatbomber 27 — 5y
Ad

Answer this question