How do I make a button which makes a part turn into a deadly block

I want to make a button which makes a part into a lava block
I haven’t scripted in a while and my knowledge is all gone. I decided to come back into the scripting stuff.

Can anyone help?

1 Like

Assuming its a ClickDetector

Connection = nil -- will be used
Active = false -- will be used

CD.MouseClick:Connect(function(player)
  if not Active then -- if Active is false
      Connection = Part.Touched:Connect(function(part) -- Creates Connection
 -- code
      end)
   else -- if Active is true
      if Connection then -- if Connection isnt nil
         Connection:Disconnect() -- Disconnects Event
      end
      Connection = nil
   end
   Active = not Active -- if false then true, if true then false
end)


With the ProximityPrompt, Its the same process

1 Like

You need of put 1 server script in the button and other script in ServerStorage

--Put this Script in Button

local Button = script.Parent
local Part = workspace.Part

Button.MouseButton1Click:Connect(function()
	local Script = game.ServerStorage.Script:Clone()
	Script.Parent = Part
end)
--Put this Script in ServerStorage

local Part = script.Parent

Part.Material = Enum.Material.CrackedLava
Part.Color = Color3.new(1, 0, 0)

Part.Touched:Connect(function(Hit)
	local Humanoid = Hit.Parent:FindFirstChild("Humanoid")
	if Humanoid then
		Humanoid.Health = 0
	end
end)
1 Like

Thats not what they are asking, they are asking how to make a Part Deadly with a Button Click

2 Likes

Hi👋,

local lavaBlock = false

script.Parent.MouseClick:Connect(function()
      if lavaBlock ==false then
           lavaBlock = true
      else
           lavaBlock = false
      end
end)

script.Parent.Parent.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") and lavaBlock == true then 
hit.Parent:FindFirstChild("Humanoid").Health -= 10
    end
end)

This will be added in a ClickDetector that is inserted in a Part, this script will be ServerSide.

Hope i helped! :sweat_smile:

Goodluck!:four_leaf_clover:

2 Likes

Hello, sorry for the late reply. This really helped me and I’m looking forward to use this a different time. I want a text button version of this script. If possible, can you help me with a text button version of this? :sweat_smile: Thanks!


local lavaBlock = false

script.Parent.MouseButton1Up:Connect(function()
      if lavaBlock ==false then
           lavaBlock = true
      else
           lavaBlock = false
      end
end)

workspace.Part.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") and lavaBlock == true then 
hit.Parent:FindFirstChild("Humanoid").Health -= 10
    end
end)

add this inside a textbutton as a localscript and change “Part” to anything you want

game:GetService("Players").PlayerAdded:Connect(function(player)
	local button = player.PlayerGui.ScreenGui.Frame.Button
	local part = game:GetService("Workspace").Part -- feel free to change the local variable paths
	button.MouseButton1Click:Connect(function() -- when the button is clicked
		part.Material = Enum.Material.CrackedLava
		part.Color = Color3.new(1,0,0)
	end)
	
	part.Touched:Connect(function(hit)
		if part.Material == Enum.Material.CrackedLava then -- checking if its lava or not
			hit.Parent:FindFirstChild("Humanoid").Health -= 100 -- this will instakill, change the value as you see fit
		end
	end)
end)

DeveloperPop’s solution would work, however it is in a LocalScript which may not be desirable.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.