Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to connect mouse.Target to a remote event?

Asked by 2 years ago

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

Log in to vote
0
Answered by 2 years ago
Edited 2 years ago

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)
0
It didnt work it says "attempt to index boolean with Target" iamnotcool235_s 27 — 2y
0
Oops, I made an error. I edited it and it should now work. T3_MasterGamer 2189 — 2y
0
Thanks iamnotcool235_s 27 — 2y
Ad

Answer this question