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

Script won't run outside of testing mode?

Basically, I want the sound to play if it meets the condition that IsActive is equal to 0. This works inside of testing mode on studio but does not when I play normally.

I already tested until the PlayerGui actually loaded.

--localscript inside of StarterGui>ScreenGui
--IsActiveInt is an integer value in Workspace
local player = game.Players.LocalPlayer
local menusound = script.PausedSound
local clicksound = script.ClickSound
IsActiveInt = game.Workspace.IsActive.Value
local PlayButton = script.Parent.Frame.MainMenu.PlayButton
local ShopButton = script.Parent.Frame.MainMenu.ShopButton
local TutorialButton = script.Parent.Frame.MainMenu.TutorialButton
local LoadingScreen = script.Parent.Frame.LoadingScreen

wait(3)

function check()
if IsActiveInt == 0 then
	menusound:Play()
end
end
check()

Thank you, Gianni

1 answer

✓ Accepted answer

Use tons of WaitForChilds.

The parent of an object always loads before the child, so using .Parent is always fine. However, when you're trying to access a child of an object, use WaitForChild unless you know it's loaded.

local player = game.Players.LocalPlayer
local menusound = script:WaitForChild("PausedSound")
local clicksound = script:WaitForChild("ClickSound")
IsActiveInt = workspace:WaitForChild("IsActive")--removed .Value
local Frame = script.Parent:WaitForChild("Frame")
local MainMenu = Frame:WaitForChild("MainMenu")
local PlayButton = MainMenu:WaitForChild("PlayButton")
local ShopButton = MainMenu:WaitForChild("ShopButton")
local TutorialButton = MainMenu:WaitForChild("TutorialButton")
local LoadingScreen = Frame:waitForChild("LoadingScreen")

wait(3)

function check()
	if IsActiveInt.Value == 0 then-- Added .Value
  	  menusound:Play()
	end
end
check()
I also shifted the .Value around. Just trust me on that one. I also added a few more variables, mostly for other variable. There was no reason to do this beside the fact that using WaitForChild after a WaitForChild gets long and might run off the screen.

I hope I helped!

Good Luck!

3 comments

0

So the problem was that I was referencing the child of the objects before it loaded?

0

Yeah, most likely.

0

That's almost always the reason why something works in studio but not online. Things aren't loaded or people don't know how to use FE.

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