So, I made and scripted a reloading mechanic for my cannon. They work completely fine if I click "Run" but if I were to click "Play" the GUI would not work at all. For example, If I press "R" on Run mode, a text will appear saying "reloading" for 2 seconds. But when I press "R" in Play mode, the text will not appear at all. Here is the script that toggles the reloading stuff.
local ammoLeft = 20 local reloaded = false -- The amount of cannon balls reloaded (Should only be either true or false) local reloading = false CannonGUIS = game.StarterGui.GameGUIs.CannonStuff -- All GUI's related to the cannon. function onKeyPress(inputObject, gameProcessedEvent) if inputObject.KeyCode == Enum.KeyCode.F then if reloaded then Fire() script.Parent.Parent.Barrel.ExplodeSound2:Play() else Reload() end end end function Reload() if not reloading and ammoLeft > 0 then CannonGUIS.Ammo.ReloadingText.Visible = true reloading = true print("Reloading.") wait(2) CannonGUIS.Ammo.Amount.Value = CannonGUIS.Ammo.Amount.Value - 1 --CannonGUIS.Ammo.AmountText.Text = CannonGUIS.Ammo.Amount.Value ammoLeft = ammoLeft - 1 reloaded = true CannonGUIS.Ammo.ReloadingText.Visible = false print("Reloaded.") reloading = false elseif reloading then return elseif ammoLeft == 0 then CannonGUIS.Ammo.NoMoreCannonBalls.Visible = true end end game:GetService("UserInputService").InputBegan:connect(onKeyPress)
Oh and this script is inside a Model in Workspace.
Anyone know what's wrong? Thanks!
That is because you are only changing the StarterGui, not the Player's Gui, try putting this script to the StarterGui and change
CannonGUIS = game.StarterGui.GameGUIs.CannonStuff
to
CannonGUIS = script.Parent.GameGUIs.CannonStuff