Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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!

2 comments

0

Your problem is easier than mine.

0

Haha.

1 answer

✓ Accepted answer

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

1 comment

0

Works like a charm, thanks mate.

This discussion is preserved as it was. New answers, comments, and votes are closed.