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

How to iterate string value children?

Asked by 5 years ago

I have a part, Gamers, that I add StringValues to in a script. The StringValue.Name and Value are set to a player name. However, when I get the children of the Gamers part and attempt to iterate the string values all I get are StringValue.Name = 'Value' and StringValue.Value = 'Value'. Below is some sample code:

local gamers = game.Workspace.Gamers:GetChildren()
for i = 1, #gamers do
    print("the string", gamers[i], gamers[i].Name, gamers[i].Value)
end

The above code just prints: "the string Value Value"

Any idea what's going on?

1 answer

Log in to vote
0
Answered by 5 years ago

There are a couple possibilities:

  • You have a script on the client trying to change the StringValue instead of the server. Due to FilteringEnabled, the server would not be updated of such changes. To fix this problem, you need to rewrite the script to work on the server, see below.
  • Your script that changes the StringValues is on the server, but it simply isn't working. To fix this problem, I recommend using print statements at various points in your scripts to determine what is and isn't working. If this doesn't help, you'll probably need to post the script.

An example of a server-side script that might do what you want:

local gamers = workspace.Gamers:GetChildren()
game.Players.PlayerAdded:Connect(function(player)
    local value = Instance.new("StringValue")
    value.Name = player.Name
    value.Value = player.Name
    value.Parent = gamers
    player.AncestryChanged:Connect(function() -- Occurs when the player leaves the game
        value:Destroy()
    end)
end)
0
Thanks for your reply. Neither the script that populates the gamers string values, nor the script that attempts to read them are local scripts. funitude 5 — 5y
0
Have you tried adding 'print' statements to verify that your script is populating the string values at all? Not only that it runs, but what it's trying to assign to each StringValue? chess123mate 5873 — 5y
Ad

Answer this question