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

Why is this basic function script not working?

Output says nothing. I don't know how much I need to explain because this script is pretty self-explanatory:

wait()
a = script.Parent.Home.TeamName
b = script.Parent.Home.Score
c = script.Parent.Away.TeamName
d = script.Parent.Away.Score
e = game.Players:GetChildren()
function Cosby()
    e.PlayerGui.Score.Home.Text = a.Text .. ": " .. b.Text
    e.PlayerGui.Score.Away.Text = c.Text .. ": " .. d.Text
end
script.Parent.Update.MouseButton1Click:connect(Cosby)

2 answers

✓ Accepted answer
e = game.Players:GetChildren()
e.PlayerGui.Score.Home.Text = a.Text .. ": " .. b.Text

This is your problem. But first, you variables should reflect what they equal for readability purposes. This need will become more apparent as you write longer series of code throughout multiple days. You might have to check back because you don't remember what they equal.


But you actual functionality problem has to do with what GetChildren returns.

GetChildren gives you a list. A list does not have a PlayerGui. Thus it will error.

Therefore what you need to do, assuming you want it to update for everyone, is use a for loop to get each individual value from the list.

for index, player in ipairs(e) do
	player.PlayerGui Etc etc
end

I highly recommend to use a Local Script since they make it so much easier to access the Player etc.

	local Player = game.Players.LocalPlayer
	local PlayerGui = Player:WaitForChild("PlayerGui")
a = script.Parent.Home.TeamName.Text
b = script.Parent.Home.Score.Text
c = script.Parent.Away.TeamName.Text
d = script.Parent.Away.Score.Text
function Cosby()
    PlayerGui.Score.Home.Text = a .. ": " .. b
    PlayerGui.Score.Away.Text = c .. ": " .. d
end
script.Parent.Update.MouseButton1Click:connect(Cosby)

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