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

Script won't run outside of testing mode?

Asked by 7 years ago

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

Log in to vote
1
Answered by 7 years ago
Edited 7 years ago

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!

0
So the problem was that I was referencing the child of the objects before it loaded? GianniKun 40 — 7y
0
Yeah, most likely. User#11440 120 — 7y
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. User#11440 120 — 7y
Ad

Answer this question