Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why won't my GUI create an explosion?

Asked by 9 years ago

I am doing tests for a gun making simulator and I need a button to remotely detonate it, but the script I made won't work. It is in a local script and it does not give me any errors.

local Explosive = game.Workspace.Model.Mechanism
local Screen = Instance.new("ScreenGui")
local Button = Instance.new("TextButton")
Screen.Parent = game.StarterGui
Button.Parent = Screen
Button.Text = "FIRE!!"
Button.Position = UDim2.new(0, 50, 0, 100)
Button.Size = UDim2.new(0, 80, 0, 50)
Button.BackgroundColor3 = Color3.new(200,0,0)
function explode()
    local ex = Instance.new("Explosion")
    ex.BlastPressure = 99999999
    ex.BlastRadius = 50
    ex.Parent = Explosive
    ex.DestroyJointRadiusPercent = 0
    ex.Position = Explosive.Position
end
wait(1)
Button.MouseButton1Down:connect(explode)

1 answer

Log in to vote
0
Answered by 9 years ago

Parent it to workspace, and don't put the GUI in the StarterGui. Parent it to the local player.

here:

local Explosive = workspace.Part

local player = game:GetService("Players").LocalPlayer
local playergui = player.PlayerGui

local Screen = Instance.new("ScreenGui", playergui)
local Button = Instance.new("TextButton", Screen)

Button.Text = "FIRE!!"
Button.Position = UDim2.new(0, 50, 0.5, 0)
Button.Size = UDim2.new(0, 80, 0, 50)
Button.BackgroundColor3 = Color3.new(200,0,0)

Button.MouseButton1Down:connect(function()
    local ex = Instance.new("Explosion",workspace)
    ex.BlastPressure = 99999999
    ex.BlastRadius = 50
    ex.DestroyJointRadiusPercent = 0
    ex.Position = Explosive.Position
end)
Ad

Answer this question