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

mouse is nil when its defined 4 lines above?

so im having some issues, this script is a regular script in a tool it keeps saying that mouse is a nil value

heres the code that i made

local player = script.Parent.Parent.Parent
local mouse = player:GetMouse()

script.Parent.Activated:Connect(function()
	local kaboom = Instance.new("Explosion",workspace)
	kaboom.Position = mouse.Hit.Position
end)

3 comments

0

Where is the script located?

0

Also is this script local?

0

The script has to be local, and you can set player as game.Players.LocalPlayer

1 answer

✓ Accepted answer

Thanks to @Shawnyg, you get set the player in a LocalScript with the LocalPlayer property in the Players service.

local playerServ = game:GetService("Players") -- Get the players service
local player = playerServ.LocalPlayer -- Use the LocalPlayer property
local mouse = player:GetMouse()

script.Parent.Activated:Connect(function()
    local kaboom = Instance.new("Explosion",workspace)
    kaboom.Position = mouse.Hit.Position
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.