Is there a better way of doing this script?

The script is just to show how much money the player has. Not sure if it could cause lag or not. It works fine i just want to know if there is a better way to do it.

wait()
local bigcheese69800 = false
cashvalue = game.Players.LocalPlayer.leaderstats.Cash


repeat
	wait(0.1)
	script.Parent.Text = ("$").. cashvalue.Value
until bigcheese69800 == true

Use a .Changed Event so be more Efficient, doesnt make sense to update every second if you can just fire it when something actually happens.

4 Likes
local player = game.Players.LocalPlayer
local leaderstats = player:WaitForChild("Leaderstats")
local Cash = leaderstats:WaitForChild("Cash")
local text = script.Parent

local function Update()
	text.Text = "$"..Cash.Value
end

Update() -- run when the code starts
Cash.Changed:Connect(Update) -- updates when the cash value changes

yes, there is a better way of doing it.

if u wanna use runservice u can

local player = game.Players.LocalPlayer
local leaderstats = player:WaitForChild("Leaderstats")
local Cash = leaderstats:WaitForChild("Cash")
local text = script.Parent
local RunService = game:GetService("RunService")

local function Update()
	text.Text = "$"..Cash.Value
end

RunService.RenderStepped:Connect(Update)

loops can cause lag.

2 Likes

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