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

Attempt to index nil with 'Hit'?

This is my script:

local Tool = script.Parent
local cool = false -- Debounce
local mouse = game:GetService("Players").LocalPlayer:GetMouse()
Tool.Activated:Connect(function(mouse)
	if cool == false then
		cool = true
		local pos = mouse.Hit.Position  -- Error here
		Tool.RemoteEvent:FireServer(pos)
		wait(1)
		cool = false
	end
end)

This is a local script and I put this in a tool. I'm trying to get the player's mouse position and send it to the script that activates when the remote event is fired. This error stopped all of my script. How can I fix this?

1 comment

0

put it in a code block please

1 answer

✓ Accepted answer

The problem with your script is the 'mouse' parameter inside the .Activated. Activated does not have any parameters like that.

Here's a fixed script :

local Tool = script.Parent 
local cool = false -- Debounce 
local mouse = game:GetService("Players").LocalPlayer:GetMouse()
 
Tool.Activated:Connect(function() 
if cool == false then cool = true 
local pos = mouse.Hit.Position 

Tool.RemoteEvent:FireServer(pos) 

wait(1) 
cool = false 
end 
end) 

1 comment

0

Thank you!

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