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

How to connect mouse.Target to a remote event?

Im trying to script that destroys parts when you click it but i cant connect mouse.Target to a remove event this is the script that i have

This is the local script

local UserInputService = game:GetService("UserInputService") local ReplicatedStorage = game:GetService("ReplicatedStorage") local RemoteEvent = ReplicatedStorage:WaitForChild("RemoteEvent")

UserInputService.InputBegan:Connect(function(input, mouse) if input.UserInputType == Enum.UserInputType.MouseButton1 then mouse.Target:FireServer(mouse) end end)

This is the server script

local ReplicatedStorage = game:GetService("ReplicatedStorage") local RemoteEvent = ReplicatedStorage:WaitForChild("RemoteEvent")

mouse.Target.OnServerEvent:Connect(function(player, mouse) mouse.Target:Destroy() end)

1 answer

✓ Accepted answer

You are trying to fire a mouse target, which is OBVIOUSLY not a remote event. It can result in errors and next time check the most obvious things first. In local script change the entire script to

local UserInputService = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEvent = ReplicatedStorage:WaitForChild("RemoteEvent")

UserInputService.InputBegan:Connect(function(input, gameProcessed) 
	if input.UserInputType == Enum.InputType.MouseButton1 then
		RemoteEvent:FireServer(game.Players.LocalPlayer:GetMouse().Target)
	end
end)

and change the server script to


local ReplicatedStorage = game:GetService("ReplicatedStorage") local RemoteEvent = ReplicatedStorage:WaitForChild("RemoteEvent")

RemoteEvent.OnServerEvent:Connect(function(player, mouseTarget) mouseTarget:Destroy() end)

3 comments

0

It didnt work it says "attempt to index boolean with Target"

0

Oops, I made an error. I edited it and it should now work.

0

Thanks

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