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

Coins GUI not working?

I want the GUI to display the players coins. I have tryed this and it dosent want to work?? Aneyone got a solution

Leaderboard:

game.Players.PlayerAdded:connect(function(player)
	
	stats = Instance.new ("IntValue", player)
	stats.Name = "leaderstats"
	
	coins = Instance.new ("IntValue", stats)
	coins.Name = "Coins"
	coins.Value = 10
	
end)

game.Players.PlayerRemoving:connect(function(player)
	
end)

GUI script:

while true do
	if script.Parent.Text == "0" then
	script.Parent.Text = game.Players.leaderstats.Coins.Value
	end
end

4 answers

✓ Accepted answer

Gui Script

local player = game.Players.LocalPlayer
script.Parent.Text = player.leaderstats.Coins.Value -- added this line to initialise the gui.

player.leaderstats.Coins.Changed:connect(function()
    script.Parent.Text = player.leaderstats.Coins.Value
end) -- Wrapping your function like this ensure it only changes when the value changes, this is better than a while loop and is called an anonymous function. 

I've defined player as a local value to match the games local player, this has to be in a localscript to work, localscripts should work fine inside of the players character, the current camera, the players backpack or the players gui.

14 comments

0

do i use localscript or script??

0

LocalScript

0

ok, thansk, but idnt the same as the last answer

0

nope, the game loads, but.. it the gui still says 0, not 10

0

I changed the script, as you had the Coins with a lowercase c and value with a lowercase V. I believe they should of been capatalized. Correct me if im wrong

0

I was wrong, I just corrected that for you, sorry :).

0

what should be the Parent of the LocalScript. Currently I have it in the TextBox

0

TextBox is fine

0

It still dosent work?? Can you try in a Single Player wolrd too?

0

maybe it has something to do with leaderboard?

0

okay, fixed it, should work fine now. Tested it for you too, I had no problems.

0

OMG, thank you soo much. Works :D

0

Hey do you think you could help me with a few scripts to my game?? willing to work out a cost or something???

0

Hey, I need the script to now look at your teams kills, like in a round with blue vs red and I need it so blues GUI displays all of blues team kills put together, how could I edit for that reason?

In your GUI Script, on line 3, you aren't pointing to a player which is why it's not working. Make sure the GUI script is in a LocalScript and change line 3 to look like this: script.Parent.Text = game.Players.LocalPlayer.leaderstats.Coins.Value. I hope this helps!

11 comments

0

Where should the local script be?? In the starter GUi, the screen gui, the text box??

0

It just makes my character not even load now. When I click pla it just says Waiting for character for 5 minutes

0

The LocalScript should be a child of the TextBox.

0

It still just says Waiting for Character?? IS it just my internet??

0

Yes, you should either reconnect to your router/modem, restart your computer, or restart your router/modem and try it again.

0

ok

0

Ok, it still didnt work. It has the 10 coins in the leaderboard, but 0 in the gui

0

Nope nothing. I have restarted comp and router. It has to be the local script, cause when I removed it it worked. Is their a way to do it without localscript???

0

Copy and Paste what is inside the LocalScript here so I can look at it.

0

while true do if script.Parent.Text == "0" then script.Parent.Text = game.Players.LocalPlayer.leaderstats.Coins.Value end end

0

NinjoOnline, try this: while true do script.Parent.Text = game.Players.LocalPlayer.leaderstats.Coins.Value end

Make sure that you're testing this script online, as most leaderboard scripts don't work in solo mode. Also, don't forget to add a wait() just before the end in your while loop, if you don't it will cause your computer to run out of memory. Anyways, if it still doesn't work, is there anything in the output ?

1 comment

0

Still not working. I have put it on a place. The leaderboard loads up, just not the GUI dosent work

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