I'm trying to change the text when a sound ends, but it won't work. Can somebody please help me solve this problem?
--IMPORTANT I'm using the self, and for some time this seems to have worked but when I try to make sure it changes when a sound plays when the gun fires so it can actually have an accurate reload system.
-------------------------------------------------------------------------------------- --------------------[ CHARACTER LOADING ]--------------------------------------------- -------------------------------------------------------------------------------------- repeat wait() until game.Players.LocalPlayer.Character repeat wait() until game.Players.LocalPlayer.Character:IsDescendantOf(game.Workspace) wait(1 / 20) -------------------------------------------------------------------------------------- --------------------[ CONSTANTS ]----------------------------------------------------- -------------------------------------------------------------------------------------- local Players = game:GetService("Players") local TweenService = game:GetService("TweenService") local ReplicatedStorage = game:GetService("ReplicatedStorage") local Player = game.Players.LocalPlayer local PlayerGui = Player.PlayerGui local CustomHUD = script:WaitForChild("CustomHUD") local Engine = ReplicatedStorage:WaitForChild("ACS_Engine") local GunModels = Engine:WaitForChild("GunModels") local Gun = script.Parent local Ammo local StoredAmmo local AttributeAmmo = Gun:GetAttribute("Ammo") local AttributeAmmoChanged = Gun:SetAttribute("Ammo") local Type = Gun:GetAttribute("GunType") local WeaponInHand, WeaponTool, WeaponData, AnimData WeaponTool = Gun WeaponData = require(Gun:WaitForChild("ACS_Settings")) WeaponInHand = GunModels:WaitForChild(Gun.Name) Ammo = WeaponData.AmmoInGun StoredAmmo = WeaponData.StoredAmmo -------------------------------------------------------------------------------------- --------------------[ TOOL SELECTION AND DESELECTION ]-------------------------------- -------------------------------------------------------------------------------------- function onEquipped() print(WeaponData.Ammo) CustomHUD.Frame.GunType.Text = Type CustomHUD.Parent = PlayerGui if CustomHUD.Frame.Position == UDim2.new(0.7, 0,1.1, 0) then wait(.1) CustomHUD.Frame:TweenPosition(UDim2.new(0.7, 0,0.794, 0), "Out", .75) end CustomHUD.Frame.AmmoBase.AmmoBackGround.AmmoAmount.Text = WeaponData.Ammo.."/".. WeaponData.Ammo WeaponInHand.Handle.Muzzle.Fire.Ended:Connect(function() Ammo = WeaponData.Ammo - 1 CustomHUD.Frame.AmmoBase.AmmoBackGround.AmmoAmount.Text = WeaponData.AmmoInGun.."/".. WeaponData.Ammo end) end function onUnequipped(deleteTool) if CustomHUD.Parent == PlayerGui then CustomHUD.Parent = script if CustomHUD.Frame.Position == UDim2.new(0.7, 0,0.794, 0) then wait(1) CustomHUD.Frame.Position = UDim2.new(0.7, 0,1.1, 0) end end end Gun.Equipped:connect(onEquipped) Gun.Unequipped:connect(function() onUnequipped(false) end)
I was able to find a way to fix it via a bindable event. I even finished the reloading.
-------------------------------------------------------------------------------------- --------------------[ CHARACTER LOADING ]--------------------------------------------- -------------------------------------------------------------------------------------- repeat wait() until game.Players.LocalPlayer.Character repeat wait() until game.Players.LocalPlayer.Character:IsDescendantOf(game.Workspace) wait(1 / 20) -------------------------------------------------------------------------------------- --------------------[ CONSTANTS ]----------------------------------------------------- -------------------------------------------------------------------------------------- local Players = game:GetService("Players") local TweenService = game:GetService("TweenService") local ReplicatedStorage = game:GetService("ReplicatedStorage") local Player = game.Players.LocalPlayer local PlayerGui = Player.PlayerGui local CustomHUD = script:WaitForChild("CustomHUD") local Engine = ReplicatedStorage:WaitForChild("ACS_Engine") local Events = ReplicatedStorage:WaitForChild("Events") local GunModels = Engine:WaitForChild("GunModels") local Gun = script.Parent local Ammo local StoredAmmo local AttributeAmmo = Gun:GetAttribute("Ammo") local Type = Gun:GetAttribute("GunType") local WeaponInHand, WeaponTool, WeaponData, AnimData WeaponTool = Gun WeaponData = require(Gun:WaitForChild("ACS_Settings")) WeaponInHand = GunModels:WaitForChild(Gun.Name) Ammo = WeaponData.AmmoInGun StoredAmmo = WeaponData.StoredAmmo -------------------------------------------------------------------------------------- --------------------[ TOOL SELECTION AND DESELECTION ]-------------------------------- -------------------------------------------------------------------------------------- function onEquipped() print(Ammo) CustomHUD.Frame.GunType.Text = Type CustomHUD.Parent = PlayerGui if CustomHUD.Frame.Position == UDim2.new(0.7, 0,1.1, 0) then wait(.1) CustomHUD.Frame:TweenPosition(UDim2.new(0.7, 0,0.794, 0), "Out", .75) end CustomHUD.Frame.AmmoBase.AmmoBackGround.AmmoAmount.Text = Ammo.."/".. WeaponData.Ammo Events.HUDEvent1.Event:Connect(function(CurrentAmmo) CustomHUD.Frame.AmmoBase.AmmoBackGround.AmmoAmount.Text = CurrentAmmo.."/".. WeaponData.Ammo end) Events.HUDEvent2.Event:Connect(function(CurrentAmmo) CustomHUD.Frame.AmmoBase.AmmoBackGround.AmmoAmount.Text = CurrentAmmo.."/".. WeaponData.Ammo end) end function onUnequipped(deleteTool) if CustomHUD.Parent == PlayerGui then CustomHUD.Parent = script if CustomHUD.Frame.Position == UDim2.new(0.7, 0,0.794, 0) then wait(1) CustomHUD.Frame.Position = UDim2.new(0.7, 0,1.1, 0) end end end Gun.Equipped:connect(onEquipped) Gun.Unequipped:connect(function() onUnequipped(false) end)