ive been trying to make an explosion be configured from a ui, updating its blast radius and pressure, but it just doesnt update at all, it stays at the default radius and pressure no matter what i try, ive tried looping for the script to track the text on the textbox but to no avail.
heres the code:
script.Parent.Touched:Connect(function(hit)
local humanoid = hit.Parent:FindFirstChild("Humanoid")
local configs = game.StarterGui.ExplodeBlockConfig
local blastRadiusText = configs.Frame.BlastRadiusAmount.Text
local blastPressureText = configs.Frame.BlastPressureAmount.Text
local blastRadius = tonumber(blastRadiusText)
local blastPressure = tonumber(blastPressureText)
local explosion = Instance.new("Explosion")
explosion.Position = script.Parent.Position
explosion.Parent = game.Workspace
explosion.BlastRadius = blastRadius
explosion.BlastPressure = blastPressure
game:GetService("Debris"):AddItem(explosion, 4)
end)
please leave some feedback as it helps me improve my scripting. thanks!
Why are you getting the configuration from the StarterGui? You should be getting it from either the Parent, Descendant or PlayerGui.
You have 2 Frames for blastRadius and blastPressure, there might be a conflict between there.
Are you using a Frame or a TextBox to know the input of them to later then set to blastRadius and blastPressure?
This can be my solution, for now.
Put in a Local script.
-- replace Part with your part, make sure its a BasePart.
local Debris = game:GetService("Debris")
local Player = game.Players.LocalPlayer
Part.Touched:Connect(function(hit)
local Humanoid = hit.Parent:FindFirstChildOfClass("Humanoid")
local Config = Player.PlayerGui.ExplodeBlockConfig
local blastRadius = tonumber(Config.BlastRadius.Text)
local blastPressure = tonumber(Configs.BlastPressure.Text)
local Explosion = Instance.new("Explosion")
Explosion.Name = "Explosion"
Explosion.Position = Part.Position
Explosion.Parent = workspace
Explosion.BlastRadius = blastRadius
Explosion.BlastPressure = blastPressure
Debris:AddItem(Explosion, 4)
end)
Im currently on phone right now, so I don’t know if it will still return an error.