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

How can I fix this problem?

Asked by
mine248 40
9 years ago

So, when I was making a game, I made my code, and tested it on ROBLOX Studio. It worked. But, in ROBLOX Player, it failed to work.

The code was:

01local Background1 = script.Parent.Background1
02local Background2 = script.Parent.Background2
03local Background3 = script.Parent.Background3
04 
05script.Parent.Background1.Play.MouseButton1Click:connect(function()
06    Background1:Destroy()
07    Background2.Visible = true
08end)
09 
10script.Parent.Background2.Normal.MouseButton1Click:connect(function()
11    Background2:Destroy()
12    Background3.Visible = true
13end)

Are there any solutions?

1 answer

Log in to vote
1
Answered by
dyler3 1510 Moderation Voter
9 years ago

I believe the problem is that the code is running too quickly for the models to load into the game. You need to add WaitForChild(), or this line of code with each Background:

1repeat wait until script.Parent.Background1
2local Background1 = script.Parent.Background1
3repeat wait until script.Parent.Background2
4local Background2 = script.Parent.Background2
5repeat wait until script.Parent.Background3
6local Background3 = script.Parent.Background3

if you want to use WaitForChild(), then try this bit of code:

1local Background1 = script.Parent:WaitForChild("Background1")
2local Background2 = script.Parent:WaitForChild("Background2")
3local Background3 = script.Parent:WaitForChild("Background3")

The WaitForChild()method is clearly more efficient, however both of these will still work, as they both pretty much do the same thing, and wait for the models to load in.


Anyways, I believe the code should work correctly now. If you have any further problems or questions, please leave a comment below. Hope I helped :P

0
This is a button function and there are no outsider variables, meaning this will never run until triggered. Therefore, there isnt a point for WFC here unmiss 337 — 9y
Ad

Answer this question