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.
01 | local Explosive = game.Workspace.Model.Mechanism |
02 | local Screen = Instance.new( "ScreenGui" ) |
03 | local Button = Instance.new( "TextButton" ) |
04 | Screen.Parent = game.StarterGui |
05 | Button.Parent = Screen |
06 | Button.Text = "FIRE!!" |
07 | Button.Position = UDim 2. new( 0 , 50 , 0 , 100 ) |
08 | Button.Size = UDim 2. new( 0 , 80 , 0 , 50 ) |
09 | Button.BackgroundColor 3 = Color 3. new( 200 , 0 , 0 ) |
10 | function explode() |
11 | local ex = Instance.new( "Explosion" ) |
12 | ex.BlastPressure = 99999999 |
13 | ex.BlastRadius = 50 |
14 | ex.Parent = Explosive |
15 | ex.DestroyJointRadiusPercent = 0 |
16 | ex.Position = Explosive.Position |
17 | end |
18 | wait( 1 ) |
19 | Button.MouseButton 1 Down:connect(explode) |
Parent it to workspace, and don't put the GUI in the StarterGui. Parent it to the local player.
here:
01 | local Explosive = workspace.Part |
02 |
03 | local player = game:GetService( "Players" ).LocalPlayer |
04 | local playergui = player.PlayerGui |
05 |
06 | local Screen = Instance.new( "ScreenGui" , playergui) |
07 | local Button = Instance.new( "TextButton" , Screen) |
08 |
09 | Button.Text = "FIRE!!" |
10 | Button.Position = UDim 2. new( 0 , 50 , 0.5 , 0 ) |
11 | Button.Size = UDim 2. new( 0 , 80 , 0 , 50 ) |
12 | Button.BackgroundColor 3 = Color 3. new( 200 , 0 , 0 ) |
13 |
14 | Button.MouseButton 1 Down:connect( function () |
15 | local ex = Instance.new( "Explosion" ,workspace) |
16 | ex.BlastPressure = 99999999 |
17 | ex.BlastRadius = 50 |
18 | ex.DestroyJointRadiusPercent = 0 |
19 | ex.Position = Explosive.Position |
20 | end ) |