How Would I Make a Button That Explodes a Player on Click (With Delay so There's No Spam)?

I am working on updating my game, Ride a Box Into Shedletsky’s Face, and I want to know how I can make a button that explodes the player whenever they click it.

I’ve looked on YouTube, DevForum, Google, and some more Roblox Developer websites to find the answer but I’m not getting the same results I’m looking for.

Video of button:

The script:

local clicked = script.Parent.ClickDetector.MouseClick
local part = script.Parent

clicked:Connect(function()
	part.Position = Vector3.new(2708.001, 18846.492, -1361.788)
	part.BrickColor = BrickColor.new("Really red")
	
	wait(1.6)
	
	part.Position = Vector3.new (2708.001, 18846.492, -1361.936)
	part.BrickColor = BrickColor.new("Lime green")
	
	end)

Thanks, if anyone could help it would be appreciated.

2 Likes

Use a debounce to work around the spam and get the character on who clicked it.

local Explosion = Instance.new("Explosion", workspace)
explosion.Position = character:WaitForChild("HumanoidRootPart").Position
2 Likes

I added in your explosion script without the debounce. Whenever I click it, it does nothing but what it did without an explosion script. It underlines character in blue.

local clicked = script.Parent.ClickDetector.MouseClick
local part = script.Parent
local explosion = Instance.new("Explosion", workspace)

clicked:Connect(function()
	part.Position = Vector3.new(2708.001, 18846.492, -1361.788)
	part.BrickColor = BrickColor.new("Really red")
	explosion.Position = character:WaitForChild("HumanoidRootPart").Position
	
	wait(1.6)
	
	part.Position = Vector3.new (2708.001, 18846.492, -1361.936)
	part.BrickColor = BrickColor.new("Lime green")
	
	end)

You need to get the player and the character of who pressed it.

I’m new to scripting, I’m more of a texture and a model guy. By any chance, could you tell me how?

local clicked = script.Parent.ClickDetector.MouseClick
local part = script.Parent
local debounce = false

clicked:Connect(function(player)
	if not debounce then
		debounce = true
		
		part.Position = Vector3.new(2708.001, 18846.492, -1361.788)
		part.BrickColor = BrickColor.new("Really red")
		
		local explosion = Instance.new("Explosion")
		explosion.Position = player.Character:WaitForChild("HumanoidRootPart").Position
		explosion.Parent = workspace
		
		wait(1.6)
		part.Position = Vector3.new (2708.001, 18846.492, -1361.936)
		part.BrickColor = BrickColor.new("Lime green")
		debounce = false
	end
end)
1 Like

The button animation and color changing still works and the script isn’t detecting any problems, but my character is still not exploding.

I updated the script I posted, try that one.

1 Like

That one worked! Thanks, I really couldn’t find this anywhere.

1 Like