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

I am making a minigame and it works smoothly in studio but in game it doesnt?

Asked by 5 years ago
Edited 5 years ago

So I am making a minigame and I was just making it so the textlabel would say all the stuff like etc... I testing it many times in studio mode and it worked then i tested it in the actual game and it didn't work can anyone help me with this?

Repstore = game.ReplicatedStorage
maps = Repstore.Maps:GetChildren()

    while true do       
        if game.Players.NumPlayers > 1 then
        for i, v in pairs(game.Players:GetChildren()) do
            pgui = v:WaitForChild("PlayerGui")
            pgui:WaitForChild("MainText").TextLabel.Text = "Not enough players to start!"
        end
        else
            for i, v in pairs(game.Players:GetChildren()) do
            pgui1 = v:WaitForChild("PlayerGui")
            pgui1:WaitForChild("MainText").TextLabel.Text = "Chosing map"
            wait(3)
            ranGame = math.random(1, #maps)
            gameChosen = maps[ranGame]
            for i, v in pairs(game.Players:GetChildren()) do
            pgui2 = v:WaitForChild("PlayerGui")
            pgui2:WaitForChild("MainText").TextLabel.Text = "Map chosen: ".. gameChosen.Name
            wait(3)
            gameChosenClone = gameChosen:Clone()
            gameChosenClone.Parent = game.Workspace.MapSelected
            wait(3)
            spawns = gameChosenClone.Spawns:GetChildren()
            for i,v in pairs(game.Players:GetPlayers())do
                name = v.Name
                check = game.Workspace:FindFirstChild(name)
                if check then
                    checkHumanoid = check:FindFirstChild("Humanoid")
                    if checkHumanoid then
                        check:MoveTo(spawns[i].Position)
                    end
                    end
                    end
                    end
            end
                for i, v in pairs(game.Players:GetChildren()) do
                    for i = 3, 1, 1 do
            pgui3 = v:WaitForChild("PlayerGui")
            pgui3:WaitForChild("MainText").TextLabel.Text = "Game begins in".. i
                wait(1)
            end

                for i, v in pairs(game.Players:GetChildren()) do
                    for i = 10,1, -1 do
            pgui4 = v:WaitForChild("PlayerGui")
            pgui4:WaitForChild("MainText").TextLabel.Text = "Time left ".. i
                wait(1)
                end
                end
            end
            for i, v in pairs(game.Players:GetChildren()) do
            pgui5 = v:WaitForChild("PlayerGui")
            pgui5:WaitForChild("MainText").TextLabel.Text = "Game ended"
            wait(3)
            gameChosenClone:Destroy()

            for i, v in pairs(game.Players:GetChildren()) do
                for i = 60,1,-1 do
            pgui6 = v:WaitForChild("PlayerGui")
            pgui6:WaitForChild("MainText").TextLabel.Text = "Intermission ".. i

            end
            end
            end 
            end
        wait(1)
        end
0
You cannot access the PlayerGui from the server. xdeno 187 — 5y

1 answer

Log in to vote
1
Answered by
green271 635 Moderation Voter
5 years ago

Hey there, there are a few errors with your code.

Client-Server Replication

With FilteringEnabled now being a mandatory thing, client to server replication is more important then ever. Server Scripts cannot access a player's PlayerGui, and Local Scripts cannot access certain services such as ServerStorage and ServerScriptService. You'll have to use RemoteEvents and RemoteFunctions to get around this and other restrictions.

Hints

The Hint object has been deprecated in favor of TextLabels. You should not use a Hint, rather use a TextLabel at the top of the screen.

A little side-note:

  • It is not recommended to use the 2nd argument of Instance.new. You should instead set it's parent via .Parent = X.

  • It's good practice to change your variables into local variables.

0
Hi green, i want to ask why its good to change it into local variables? wouldnt it be the same as long as its not contained within a scope other than the script itself? aazkao 787 — 5y
0
Indeed, I'd like to add on that also testing this in studio is not a sure way to ensure it works in game. I recommend as you go, test it in game every now and then. It tends to help. Conmmander 479 — 5y
0
Usage of global variables is bad practice, they clutter the global environment, and if used incorrectly, make your code messy. There's no longer an excuse to use globales anymore. If you need a variable accessible by another scope, simply set it to nil at the top of the script and define it when needed. User#19524 175 — 5y
Ad

Answer this question