Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Coins do not load correctly in the GUI?

Normal script, supposed to print the player's value of coins on their GUI, but I'm not sure why it's not? No errors seem to output, but it's just stuck on Loading... Any help is appreciated, as I'm still looking into the issue.

local Player = workspace:findFirstChild("Player")

wait(4)

if workspace:findFirstChild("Player") then
Player.Coins.Changed:connect(function(Val)
script.Parent.Text = "" .. Player.Coins.Value .. " Coins"
script.Coin.Pitch = math.random(0.8,1.3)
script.Coin:Play()
   end)
end

2 answers

✓ Accepted answer

The method you used to find a player is very unprofessional, I recommend doing this:


game.Players.PlayerAdded:connect(function(player)
	if player then
		coins = player:WaitForChild'Coins'
		coins.Changed:connect(function()
			script.Parent.Text = coins.Value .. "Coins"
			script.Coin.Pitch = math.random(0.8, 1.3)--Make sure that the "Coin" Audio is inside the script.
			script.Coin:Play()
		end)
	end
end)

Please comment if you get any error, :)

1 comment

0

I think I'm supposed to have some sort of IntValue that holds the value of the Coins. How would I create a value that would be inside the Player?

I'm assuming this is placed in a script inside a TextLabel, in which case it should be a local script. To get a player inside a local script, you can use game.Players.LocalPlayer, like this:

local Player = game.Players.LocalPlayer
local Coins = Player:WaitForChild("Coins")

Coins.Changed:connect(function(Val)
	script.Parent.Text = Coins.Value .. " Coins"
	script.Coin.Pitch = math.random(0.8,1.3)
	script.Coin:Play()
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.