Displaying Leadersats on a GUI?

Hi, I am trying to display a certain players leaderstats on a billboard GUI. This “Certain Player” is the player that clicked a ClickDetector.

When clicked, it only displays 0, even if you have more than that. (0 is the amount of Points you get when you join.)

script.Parent.ClickDetector.MouseClick:Connect(function(player)
	local username = player.Name
	local text = script.Parent.Parent.TPart.SurfaceGui.Main.PlayerName
	local stats = player.leaderstats.Points
	
	text.Text = username
	
	while true do
		wait(0.1)
		text.Parent.Points.Text = stats.Value
	end
end)

“Points” is where the points are displayed.
“Script” is where the code above is.

image

I have tried many different ways of doing this, but I couldn’t get them to work.

Any help will be greatly appreciated.

Any errors. Also unrelated, I recommend not using while true do for your points updater. This method is inefficient. I would use Points.Changed and update it then.

This could be because:
You are adding points on the client. And displaying the value of the points on the server.
This means that the server doesn’t see the change of points and will keep displaying 0.

Also don’t use while wait(0.1) do use Value.Changed. This will trigger when a value’s value has been changed.

I haven’t made it so you can add points yet. I am just making it display the points at the moment. I am testing it by changing it in the leaderstats folder… is that why? Sorry, I’m not good at scripting.

I will also remove the while wait wait(0.1).

You should do the displaying of points on the client, anyways.
When adding points, you can switch from the Client to the Server using the Home Tab while playing.

Hope this solved your issue and if it did, please click the solved on my comment. Thank you :slightly_smiling_face:

2 Likes

image No errors were sent in the output.I’ll also change it to points.Changed.

Yeah, it worked! I was just wondering… It looks like I need to change the points on the server? How would I go around doing that? I’m aware I would need to use some sort of event but I have never used them…

Here’s the tricky part.

Yes, you do need to use an event.
But here’s where exploiters come in.

Exploiters can keep firing the event, and the game will think they are getting points legally.
Adding some sort of “Key” would stop MOST of them, as they are just random skids with free executors.

You can do some more research on how to secure your event. The first thing you should do is add a server sided cooldown, as they can’t bypass that.

What I meant by key:
For example you can,

--Client script
local key = 195959

event:FireServer(key)
--Server Script
local key = 195959

function gotConnection(player, GotKey)

if GotKey == key then
--give the player klicks
else
player:Kick()
end

event.OnServerEvent:Connect(gotConnection)

Even tho this won’t protect your game from exploiters, it will still at least some of them.
If your wondering why this won’t work it’s because,

Exploiters can read what gets sent/received from events, read local scripts, and so on. But It will stop the ones who can’t/don’t know how to do this.

This can easily and I mean very easily get bypassed. So as I said, you should do some research.

1 Like

Thanks for the detailed reply, I’ll look more into stopping exploiters and using events. Thanks!

1 Like