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

Is there a way for the text to be updated all the time/ when the player touches any part?

Asked by
nanaluk01 247 Moderation Voter
9 years ago

I have a tycoon, where I have a surfacegui with some text in it, and the text updates according to how much money the player has, but it only updates when player touches the cash giver. If anyone could explain to me what I need to do to make the text update when the cash is updates/ when the player moves/ when the player touches any part in workspace(I have many models), then that would be great!

wait(2)
script.Parent.Touched:connect(function(hit)
    local player = game.Players:GetPlayerFromCharacter(hit.Parent)
    if player ~= nil then
        local cash = game.ServerStorage.PlayerMoney:FindFirstChild(player.Name)
        game.Workspace.Display.GUI.Amount.Text = "$ "..cash.Value
    end
end)

1 answer

Log in to vote
0
Answered by
xApRix 25
9 years ago

You need a function that is called whenever the players global cash is changed. When that function is called you set the display value.

Solution:

--Replace your script with this one.

local cash = game.ServerStorage.PlayerMoney:FindFirstChild(player.Name) --Getting cash value.

cash.Changed:connect(function()
    --Called when the cash value changes. 
    --(when money is added or subtracted)
    game.Workspace.Display.GUI.Amount.Text = "$ "..cash.Value 
    --Set the display value.
end)

Using the "Changed" function is extremely helpful when trying to stay away from endless loops that may lag the game ("while" loops).

Hope this helps. :)

Ad

Answer this question