Why won't this work?

Why won’t this work? Am I missing something or is something else wrong?

local winner = script.Parent
local timer = game.StarterGui.timer.timer.timer
local player = game.Players.PlayerAdded:Wait()
local character = game.Players.PlayerAdded:Wait().Character
local teams = game.Teams

while true do
	if timer.Text == "Intermission.." then
		player.TeamColor = BrickColor.new("White")
		character.Parent = workspace.PlayerWaitingFolder
	elseif timer.Text == "Round Starting" then
		player.TeamColor = BrickColor.new("Lime green")
		character.Parent = workspace.PlayerIngameFolder
		print("work")
	end
	wait(0.1)
end

What won’t work? You need to be more specific.

1 Like

Try this:

local winner = script.Parent
local teams = game.Teams
game:GetService("Players").PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
local timer = player:WaitForChild("PlayerGui"):WaitForChild("timer"):WaitForChild("timer"):WaitForChild("timer")
while true do
	if timer.Text == "Intermission.." then
		player.TeamColor = BrickColor.new("White")
		character.Parent = workspace.PlayerWaitingFolder
	elseif timer.Text == "Round Starting" then
		player.TeamColor = BrickColor.new("Lime green")
		character.Parent = workspace.PlayerIngameFolder
		print("work")
	end
	task.wait(0.1)
end
end)
end)

Also try to use remote events and local script + server script next time.

1 Like

Phew, several problems here… First you are not accessing the services properly…

game.Players --This is incorrect
game:GetService("Players") --This is correct.

Next you are pulling the “timer” gui element from “StarterGui” this does not really exist during runtime.
You want:

playerGui = player.PlayerGui

And if your going to change the PlayerGui you want to do this from the client.
Players.PlayerAdded event isn’t going to do you much good client side. If it even actually ever fires.

1.False,you can make it in two ways
2. True

You’ll have to be more specific.

I mean you are wrong, two ways to get service are correct.

No actually I’m not wrong. The correct way to retrieve the service instance is to use game:GetService(). While using “game.Service” name may sometimes work because you got lucky and the service name is actually the same name as the class. Your not getting the instance of that service your getting the class definition so no methods for that class will work as expected becuase the unique values for that instance are not available through the class definition.

A prime example of this was a post just earlier today where the OP was attempting to pull an NPC from replicated storage… He was using game.ReplicatedStorage and when running the code. He was getting errors saying that the NPC could not be located. The reason is as I just described.

1 Like

This could be taken a few steps further as well.

teams = game:GetService("Teams")

Instead of a while true loop do this;

timer:GetPropertyChangedSignal("Text"):Connect(function() 
    --- Your timer text check code here..
end)

Its nearly always better to use events then loops. You should almost never need a while loop.

1 Like

Yeah, I know, I just remade it for it to work.

This can work in the studio but it’s not 100% in a complied game.
Local players = game:GetService(“Players”) … is the clear choice.

Okay, I see. I’ll learn from this. Thank you for helping!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.