How to display new created value to a text label

I’m creating a minigame with points. When the game starts the values with the players names are created in the folder called ‘Points’ in lighting and when the game ends the values are deleted from the folder.

lol

Everything is working fine and the points are created for each player but the problem is that i want to display these points on the text label.

Here is the image:
lol2

How would i display points value of the player when the points value doesn’t exist at the moment. I don’t have any scripts to share cause i don’t know how to do it. I can send the script where the values are created.

I hope somebody could help me. Thanks!

1 Like

The quickest and easiest way to accomplish this goal is to put a LocalScript inside of this specific text label

local Players = game:GetService("Players")
local Lighting = game:GetService("Lighting")

local Player = Players.LocalPlayer
local TextLabel = script.Parent
local Points = Lighting:WaitForChild("Points")

function SetLabel(Value)
	TextLabel.Text = "Points:"..Value
end

function HandlePointValue(PointValue)
	if PointValue.Name == Player.UserId then -- This is assuming your PointsValue is named after the UserId, if not change it to how it should be indexed
		SetLabel(PointValue.Value) -- Initially set the textlabel
		local Connection = PointValue.Changed:Connect(function() -- Sets up an event to change the TextLabel whenever it changes
			SetLabel(PointValue.Value)
		end)
		
		-- You can go above and beyond and disconnect the connection when the PointValue gets destroyed if you want
	end
end

Points.ChildAdded:Connect(HandlePointValue) -- Scans for any PointsValue that gets created

for Index, Value in pairs(Points:GetChildren()) do
	HandlePointValue(Value) -- Also scans for any PointsValue if it has already been created before the ChildAdded event can pick it up
end
2 Likes

THANKS SO MUCH! It’s working perfectly.

I see you’ve gotten a solution. But, I wouldn’t recommend player point under lighting it’s the old way and exploiters pretty much can access it and modify their points, etc.

I would store the points in the serverstorage and make it server-sided.

That was just a tip.

(In the future you don’t need to care about exploiters, byfron will take care)

2 Likes

ohh I totally forgot exploiters have access to lighting. The points are server-sided already so I think it should be easy to store them in server storage now.

Thanks for such a helpful tip :+1:

1 Like

Exploiters cannot manipulate their points if they are stored inside of Lighting as there is this wonderful thing called “FilteringEnabled” which has been a thing for many years now, if they change the value it will only change for them and won’t replicate to any other clients or server

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.