Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

My game.Loaded function is not running in game? Am I doing something wrong?

I make a little loading gui, and here is the script.

local ding = script.Parent.Ding
local AAA = script.Parent.First
local BBB = script.Parent.Second

game.Loaded(function()
	print("Someone loaded...")
	print(game.Players.LocalPlayer.Name.."has loaded!")
	script.Parent.Ding.Playing = true
	
	--makes a check mark
	AAA.V.Text = "/"
	AAA.X.Text = "V"
	AAA.X.TextColor3 = "0, 255, 0"
	
	BBB.V.Text = "/"
	BBB.X.Text = "V"
	BBB.X.TextColor3 = "0, 255, 0"
	
	wait(5)
	--remove loading gui
	
	script.Parent.Parent:ClearAllChildren()

end

I never see it printed "Someone loaded..." and I done this with few bricks, not a complex game. Please help!

1 answer

✓ Accepted answer

You are trying to connect an event in order to have your code run when the event fires. This is called an event connection. As such, after you get the event, you have to follow it with :connect(function() --code end) in order to actually connect the event.

Link to the wiki for connections.

local ding = script.Parent.Ding
local firstObj = script.Parent.First --in general, use descriptive variable names
local secondObj= script.Parent.Second

game.Loaded:connect(function() --the actual connection
	print("Someone loaded...")
	print(game.Players.LocalPlayer.Name.."has loaded!")
	ding.Playing = true --you made a variable for this
	
	--makes a check mark
	firstObj .V.Text = "/"
	firstObj .X.Text = "V"
	firstObj .X.TextColor3 = Color3.fromRGB(0, 255, 0)
	
	secondObj.V.Text = "/"
	secondObj.X.Text = "V"
	secondObj.X.TextColor3 = Color3.fromRGB(0, 255, 0)
	
	wait(5)
	--remove loading gui
	
	script.Parent.Parent:ClearAllChildren()
end) --for event connections, you need to follow the "end" with ")".

Another useful link: Color3

2 comments

0

but AAA and BBB works.

0

That doesn't matter. It's difficult for us (humans) to understand them when we are reading code. This becomes very important very quickly when you code gets longer.

This discussion is preserved as it was. New answers, comments, and votes are closed.