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

Scripts and value changing?

Asked by 7 years ago
for i,v in pairs(game.Players:GetPlayers()) do
        Chillers =script.Parent.Chillers.Value
        people = script.Parent.People.Value
        Workers =script.Parent.Workers.Value
        MyWorkers =script.Parent.MyWorkers.Value
        people.Value=Chillers.Value+Workers.Value+MyWorkers.Value
        v.PlayerGui.ScreenGui.Chillers.Text=("Unemployed: "..Chillers.Value)
        v.PlayerGui.ScreenGui.Workers.Text=("Working: "..Workers.Value)
        v.PlayerGui.ScreenGui.People.Text=("Total People: "..people.Value)
        v.PlayerGui.ScreenGui.MyWorkers.Text=("Your Workers: "..MyWorkers.Value)
    end

This is in a local script and the value is on default set onto 1 so correctly the code says "unemployed: 1" but when I change the value my self. (I manually go into the properties of the value and change the number without scripts.) The gui text remains as "unemploued: 1" Can I have help for this problem.

1 answer

Log in to vote
0
Answered by 7 years ago

Unless this in a player or one of their descendants (PlayerGui, ect.) try using a server script and put it in the ServerScriptService. The problem is that this only runs once the game starts, here would be a solution:

function updategui()
for i,v in pairs(game.Players:GetPlayers()) do
        Chillers =script.Parent.Chillers.Value
        people = script.Parent.People.Value
        Workers =script.Parent.Workers.Value
        MyWorkers =script.Parent.MyWorkers.Value
        people.Value=Chillers.Value+Workers.Value+MyWorkers.Value
        v.PlayerGui.ScreenGui.Chillers.Text=("Unemployed: "..Chillers.Value)
        v.PlayerGui.ScreenGui.Workers.Text=("Working: "..Workers.Value)
        v.PlayerGui.ScreenGui.People.Text=("Total People: "..people.Value)
        v.PlayerGui.ScreenGui.MyWorkers.Text=("Your Workers: "..MyWorkers.Value)
    end
end

-- The following call the function updategui() whenever one of them is changed
script.Parent.People.Changed:connect(updategui)
script.Parent.Workers.Changed:connect(updategui)
script.Parent.Chillers.Changed:connect(updategui)

Hope this helped.

Ad

Answer this question