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

Coin value display text not working, what's the problem?

Asked by 9 years ago

The script's parent should display the player's coin value, but it isn't working. The final product should say 500000 MC (I set the value in the StarterPack to 500000).

a = script.Parent.Parent.Parent.Parent.Parent.Parent.StarterPack.Coins.Value
script.Parent.Text = a.."MC"
0
Output or it never happened. Nickoakz 231 — 9y

2 answers

Log in to vote
0
Answered by
Relatch 550 Moderation Voter
9 years ago

Pretty sure you just made small errors. Try this script. If it doesn't work, don't thumbs down. Tell me the error and see if I can fix it.

Note: Make sure to use a localscript for this. "game.Players.LocalPlayer" is only accessible through one.

while wait(10) do --loops this code every 10 seconds
    local player = game.Players.LocalPlayer --use this instead of what you had before, if the hierarchy gets messed up it will break .
    local coins = player.StarterGear:WaitForChild("Coins") --waits for "Coins", located in the player's startergear.
    script.Parent.Text = coins.Value .. "MC" --displays text on the gui.
end
Ad
Log in to vote
0
Answered by
davness 376 Moderation Voter
9 years ago

1. Don't set properties as variables, but the objects:

a = script.Parent.Parent.Parent.Parent.Parent.Parent.StarterPack.Coins
script.Parent.Text = a.Value.."MC"

2. Use changed event and not a while true loop to update the value, it will eat less resources:

a = script.Parent.Parent.Parent.Parent.Parent.Parent.StarterPack.Coins
a.Changed:connect(function()
    script.Parent.Text = a.Value.."MC"
end)

3. Using local on variables eat less resources:

local a = script.Parent.Parent.Parent.Parent.Parent.Parent.StarterPack.Coins
a.Changed:connect(function()
    script.Parent.Text = a.Value.."MC"
end)

4. Why starterpack? On ServerScriptService, insert a script, which contains the code:

game.Players.PlayerAdded:connect(function(player)
     local val = Instance.new("IntValue")
     val.Name = "Coins"
     val.Parent = player
     val.Value = 500000
    player.PlayerGui.ScreenGui.fefe.fefhtuy.ggrgd.af.Text = val.Value.."MC" -- change the hierarchy by yourself
    val.Changed:connect(function()
        player.PlayerGui.ScreenGui.fefe.fefhtuy.ggrgd.af.Text = val.Value.."MC" -- change the hierarchy by yourself
    end)
 end)

Answer this question