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

How do I make a hammer that destroys GameObjects when I'm touching them and have left clicked?

I have tried using a global variable to be true when I left click, but it doesn't work. Can someone please help?

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)

4 comments

0

my bad, made a mistake, edited local script code.

0

It hasn't worked. The Lua debugger says there is an error.

0

Tell me the error - sorry for late reply.

0

Both scripts have errors according to the debugger.

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