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

Why is my text not displaying whenever I go into "Play" mode in Studio???

Asked by
Nep_Ryker 131
6 years ago

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!

0
Your problem is easier than mine. Froredion 15 — 6y
0
Haha. Nep_Ryker 131 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

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
0
Works like a charm, thanks mate. Nep_Ryker 131 — 6y
Ad

Answer this question