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

Why does this only work in Play Solo?

Asked by 9 years ago

This LocalScript is supposed to wait until Loading is visible, open a Gui, then wait 10 seconds. If it is still visible (This is important!) Then it needs to make in invisible, and make results visible. It works perfectly in PlaySolo, but in-game doesn't work. Help please!!!

Here's the LocalScript

player = game.Players.LocalPlayer
gui = player.PlayerGui.ScreenGui
loading = script.Parent
results = gui.results

loading.Changed:connect(function(property)
 local value = property
    loading.worked.Visible = true
wait(5)
    if loading.Visible == true then
    wait(1)
        loading.Visible = false
        results.Visible = true
wait()


    end
end)
2
What is line 6 used for, and why is the identifier 'property' necessary? I do not any of those two used anywhere in the code, also, have you considered using the 'WaitForChild' method? [Parent:WaitForChild(Child)] TheeDeathCaster 2368 — 9y
0
Actually, I have no idea what that is for lol. I got this script from somebody else and edited it, idk what it is for lol Antharaziia 75 — 9y

2 answers

Log in to vote
2
Answered by
Redbullusa 1580 Moderation Voter
9 years ago

This problem is very common, but it comes with an easy fix.

Since this is a local script, it only runs in the client, unlike a server-sided script. This makes the script run a whole lot faster. More often than not, it will start sooner than when the Player and their GUIs load.

As TheAlphaStigma mentioned in the comment, you may use a WaitForChild() method to wait until the intended object is 'loaded.'

gui = player.PlayerGui:WaitForChild("ScreenGui")

You may do this for the rest of your variables that are used in your script.

results = gui:WaitForChild("results")

If that still doesn't work, then I would suggest to have the script to pause its thread until the Player itself is completely rendered using a 'repeat... until [condition]'.

repeat
    wait()
until game.Players.LocalPlayer

player = game.Players.LocalPlayer

I hope this helps!

0
Good explanation :) +1 NinjoOnline 1146 — 9y
Ad
Log in to vote
-2
Answered by 9 years ago

This happens a lot, basically because you HAVE to use a normal script instead of a basic one.

player = PUT PLAYER'S LOCATION HERE
gui = player.PlayerGui.ScreenGui
loading = script.Parent
results = gui.results

loading.Changed:connect(function(property)
 local value = property
    loading.worked.Visible = true
wait(5)
    if loading.Visible == true then
    wait(1)
        loading.Visible = false
        results.Visible = true
wait()


    end
end)
0
no you dont, theres a simpler way. You always try to use LocalScripts in StarterGui or StarterPack NinjoOnline 1146 — 9y

Answer this question