Can someone explain why it's updating all the stats showing in the gui?

:

  1. i’m trying to update the gui i made to show walkspeed stat and points stats and also damage stats, and more when i add them.

  2. the issue is, the script works and all but the gui updates all 3 stats at once whenever i spend points it tries updating every stats instead of updating only what it needs, so when i spend my points into clicking the walkspeed button it should only show the walkspeed stat that changed. but it keeps showing everything changing at once?

  3. i tried a lot of different methods and i just don’t understand what’s wrong really, if someone can at least tell me what is wrong that’ll help cause to me i don’t see the issue for the reason why it’s causing this issue. i’m not seeing the issue or something. i’m not sure what’s wrong to cause it from happening

-- local ReplicatedStorage = game:GetService("ReplicatedStorage")
local SpendPointsEvent = ReplicatedStorage.SpendPointsEvent

local player = game.Players.LocalPlayer
local leaderstats = player:WaitForChild("leaderstats")
local pointsValue = leaderstats:WaitForChild("Points")
local walkspeedValue = leaderstats:WaitForChild("Walkspeed")
local damageValue = leaderstats:WaitForChild("Damage")

local WalkspeedButton = script.Parent.WalkspeedButton
local DamageButton = script.Parent.Damage
local PointStats = script.Parent.PointStats
local WalkSpeedStat = script.Parent.WalkSpeedStat
local DamageStats = script.Parent.DamageStats

local PointsRequired = 1

local function updateStatsDisplay()
	PointStats.Text = "Points: " .. pointsValue.Value
	WalkSpeedStat.Text = "Walkspeed: " .. walkspeedValue.Value
	DamageStats.Text = "Damage: " .. damageValue.Value
end

local function increaseWalkspeed()
	if pointsValue.Value >= PointsRequired then
		SpendPointsEvent:FireServer(PointsRequired, "Walkspeed") -- Call the server-side event to spend points for Walkspeed
	else
		print("Insufficient points! You need at least 1 point to spend on Walkspeed.")
	end
end

local function increaseDamage()
	if pointsValue.Value >= PointsRequired then
		SpendPointsEvent:FireServer(PointsRequired, "Damage") -- Call the server-side event to spend points for Damage
	else
		print("Insufficient points! You need at least 1 point to spend on increasing Damage.")
	end
end

-- Set the initial text of the DisplayPointsStat TextButton with the player's current points
updateStatsDisplay()

WalkspeedButton.MouseButton1Click:Connect(increaseWalkspeed)
DamageButton.MouseButton1Click:Connect(increaseDamage)

-- Update the GUI periodically using a heartbeat loop
while wait(1) do
	updateStatsDisplay()
end

Nevermind i found out why lol i got it working!!

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