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

attempt to index local 'mouse' (a nil value) How do I fix this?

Also I want to make if you click something it destroys I have a local script and a script they are:

Script:

game.ReplicatedStorage.destroye.OnServerEvent:Connect(function(Player,mouse)
	local mouse = Player:GetMouse()
	mouse.Target:Destroy()
end)

Local script:

local mouse = game.Players.LocalPlayer:GetMouse()
mouse.Button1Down:Connect(function()
	game.ReplicatedStorage.destroye:FireServer(mouse)
end)

How do i fix this error?

2 comments

0

try using 'game:GetService("Players")' instead, whilst calling the mouse in a different variable connected to the playerShortcut?

0

If you're passing the mouse from local script you don't need to :GetMouse() in the server script, if i remember correctly - you can't even do that! I wouldn't even pass the mouse to the server script. I would only pass the part i need to destroy.

1 answer

You cannot get the mouse via a ServerScript, nor does it replicate through RemoteFunctions/Events.

You would have to send the target to destroy, but then that would allow exploiters to destroy your whole map. I'm not sure what you're even trying to do, but you would need to add some security to make sure that your whole map isn't destroyed.

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