I have tried using a global variable to be true when I left click, but it doesn't work. Can someone please help?
COMMUNITY QUESTION
How do I make a hammer that destroys GameObjects when I'm touching them and have left clicked?
1 answer
You can use a RemoteEvent for this.
RemoteEvent Code:
- make a remote event
- put this as a server script in serverscriptservice
local whitelisted = {
"BlinkyGamer99YT",
"Player1"
}
game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(target, localname)
if table.find(whitelisted, localname) then
target:Destroy()
end
end)
LocalScript Code:
- put in player GUI or starter scripts
local player = game.Players.LocalPlayer
local Mouse = player:GetMouse()
local waitforevent = game.ReplicatedStorage:WaitForChild("RemoteEvent")
Mouse.Button1Down:Connect(function()
game.ReplicatedSotrage.RemoteEvent:FireServer(Mouse.Target, player.Name)
end)
This discussion is preserved as it was. New answers, comments, and votes are closed.

4 comments
my bad, made a mistake, edited local script code.
It hasn't worked. The Lua debugger says there is an error.
Tell me the error - sorry for late reply.
Both scripts have errors according to the debugger.