How do i make a button like that where it spawn a sphere

does anyone know to make a button like that, anything will help.

2 Likes
local part = -- The part you want to click in order to spawn a sphere.

part.Touched:Connect(function(object) -- A touched function
      -- You can check to see if the object is a character here, not going to bother.
      local sphere = Instance.new('Part')
      sphere.Size = Vector3.new(1, 1, 1) -- Size, 1 is 1 stud by 1 stud.
      sphere.Shape = Enum.PartType.Sphere -- Make it a sphere
      sphere.Position = Vector3.new(0, 10, 0) -- Position it
      sphere.Parent = workspace -- Parent it
end)

Would add a debounce to prevent spamming spheres.

1 Like

Here’s a script that I would do:

local button = script.Parent
local debounce = true
button.Touched:Connect(function(hit)
    local humanoid = hit.Parent:FindFirstChild("Humanoid")
    if humanoid then
       if debounce then
          debounce = false
    local sphere = Instance.new("Part")
    sphere.Parent = workspace
    local mesh = Instance.new("Mesh")
    mesh.Parent = sphere
    mesh.whatever = "Sphere" --I don't have Roblox studio to use this lol.
    sphere.Position = Vector3.new(x,y,z)
    sphere.Anchored = false
    sphere.Size = Vector3.new(5,5,5)
    button.Position = button.Position + Vector3.new(0,-0.5,0)
    button.BrickColor = BrickColor.new("Bright green")
    wait(2)
    button.Position = button.Position + Vector3.new(0,0.5,0)
    button.BrickColor = BrickColor.new("Really red")
    debounce = true
         end
end
end)
2 Likes

Also, thank you for teaching me “.Shape”, didn’t know I could use an Enum for that.

1 Like

A simple way would be to first position a sphere in the workspace to where you want it to be spawned at, place it in ServerStorage, and do a script like this

local part = script.Parent
local sphere = game:GetService("ServerStorage").Sphere

local deb = false

part.Touched:Connect(function(hit)
	local plr = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
	if not plr or deb then return end
	deb = true
	part.BrickColor = BrickColor.Red()
	local sphereClone = sphereClone:Clone()
	sphereClone.Parent = workspace
	sphereClone.Anchored = false
	wait(5)
	part.BrickColor = BrickColor.Green()
	deb= false
end)

It works like this

When something hits the button, check if it belongs to a player, if it doesn’t or button cannot be used yet, do not continue. If it can be used, set the debounce to true, set the BrickColor to red, clone the sphere and unanchor and parent it to workspace (which should hopefully position it where you placed it before sending to ServerStorage) wait 5 seconds, and then set the brickcolor to green and debounce to false, allowing it to be used again.

You could create the sphere yourself in the code, but I just wanted to also mention another method you could do it

2 Likes

So i insert a local script into my button add the code, and put a Sphere in serverstorage

am i reading that right?

You put a regular script into the button, position a sphere where you want it to spawn at, anchor it, and put it in ServerStorage

1 Like