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

Why is this basic function script not working?

Asked by 9 years ago

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

Log in to vote
1
Answered by
Perci1 4988 Trusted Moderation Voter Community Moderator
9 years ago
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
Ad
Log in to vote
0
Answered by 9 years ago

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)

Answer this question