0

# How do you make a script so that when you click a block, it blows you up AND gives you a badge?

This issue is so oddly specific that I wasn't able to find the solution anywhere else, what's wrong with my script?

local clicked = script.Parent.ClickDetector.MouseClick
local part = script.Parent
local debounce = false
local Players = game:GetService("Players")
local IDToAward = 0 -- There's an actual ID here.

clicked:Connect(function(player)
if not debounce then
debounce = true

local explosion = Instance.new("Explosion")
explosion.Position = player.Character:WaitForChild("HumanoidRootPart").Position
explosion.Parent = workspace

debounce = false

end
script.Disabled = true
end
end)


0
Edited 13 days ago

I deleted the last post I made and made a new one so that you could get the notification (Yea, I didn't bother to edit it), I fixed the script and it should be working if done properly: (Tested and working)

local Detector = script.Parent.ClickDetector
local part = script.Parent
local debounce = false
local Players = game:GetService("Players")
local IDToAward = 0 -- There's an actual ID here.

local debTable = {} -- Since we're using a ServerScript for this, tables are more effective for debouncing

Detector.MouseClick:Connect(function(player)
if not debTable[player.Name] then
debTable[player.Name] = true

local Success, plrOwnBadge = pcall(function() -- More secure to use pcall in case if script errors
end)

if Success then
local explosion = Instance.new("Explosion")
explosion.Position = player.Character:FindFirstChild("HumanoidRootPart").Position -- The character should be loaded by the time they clicked on this, unless if they click it in like a blink
explosion.Parent = workspace