Values changing only when player resets

Hi, Im making a system when player has enough power, he gets a new belt with new damage value and name.

I got 3 Issues:

  1. Values are changing only when player resets.
  2. Damage are not changing after getting new belt.
  3. Progress bar changes only on player reset.

Im using Profile Service to save data.

Belt client:

for i, belt in pairs(BeltsModule.Belts) do
	if leaderstats:WaitForChild('Power').Value >= belt.RequiredPower then
		currentBelt = BeltsModule.Belts[i]
		
		if BeltsModule.Belts[i + 1] ~= nil then
			nextBelt = BeltsModule.Belts[i + 1]
		end
	end
	
end

print(currentBelt.Name)

local function BeltEventFire()
	while true do
		task.wait(1)
		BeltEvent:FireServer(currentBelt)	
	end	
end


task.spawn(BeltEventFire)

function UpdateProgressBar(number)
	local GreenSection = script.Parent:WaitForChild('ProgressBar').GreenSection
	GreenSection.Size = UDim2.fromScale(number, 1)
end

local ProgressTowardsNextBelt = leaderstats:WaitForChild('Power').Value / nextBelt.RequiredPower

UpdateProgressBar(ProgressTowardsNextBelt)

leaderstats:WaitForChild('Power').Changed:Connect(function()
	UpdateProgressBar(ProgressTowardsNextBelt)
end)

PowerFrame.TextLabel.Text = '💪 '..tostring(leaderstats:WaitForChild('Power').Value)..'/'..nextBelt.RequiredPower

leaderstats:WaitForChild('Power').Changed:Connect(function()
	PowerFrame.TextLabel.Text = '💪 '..tostring(player:WaitForChild('leaderstats').Power.Value)..'/'..nextBelt.RequiredPower
end)

Belt Server:

BeltEvent.OnServerEvent:Connect(function(player, CurrentBelt)
	local profile = dataManager.Profiles[player]
	if not profile then return end
	
	profile.Data.Belt = CurrentBelt.Name
	player.leaderstats.Belt.Value = profile.Data.Belt
	
	profile.Data.BeltMultiplier = CurrentBelt.Multiplier
	player.PlayerValues.BeltMultiplier.Value = profile.Data.BeltMultiplier
	
	profile.Data.PlayerDamage = CurrentBelt.Damage
	player.PlayerValues.BeltMultiplier.Value = profile.Data.PlayerDamage
	
	profile.Data.PlayerHp = CurrentBelt.Health
	player.PlayerValues.PlayerHp.Value = profile.Data.PlayerHp

end)

If you need other scripts, I can give them too

I’d rather need to see the hiearchy of everything. Like when it says

if leaderstats:WaitForChild('Power')

Is "leaderstats"a script, a folder or something like that?

oh

local PowerFrame = script.Parent:WaitForChild('PowerFrame')

local player = game.Players.LocalPlayer
local leaderstats = player:WaitForChild('leaderstats')

local RepStorage = game:GetService('ReplicatedStorage')
local BeltsModule = require(RepStorage:WaitForChild('Belts'))
local BeltEvent = RepStorage:WaitForChild('Remotes'):WaitForChild('BeltEvent')

local nextBelt = nil
local currentBelt = nil

question is still unsolved

I think you forgot create a loop to detected if player‘power > belt.requiredpower.
If you put the localscript in starterscript.it will be copied to player.playerscriot and triggered once when everytime a player reset.
So you should change your localscript to

task.spawn(function()
while true do
task.wait(anytime)
for i, belt in pairs(BeltsModule.Belts) do
if leaderstats:WaitForChild(‘Power’).Value >= belt.RequiredPower then
currentBelt = BeltsModule.Belts[i]

	       if BeltsModule.Belts[i + 1] ~= nil then
		  nextBelt = BeltsModule.Belts[i + 1]
	       end
        end

   end

end
end)


1 Like

emm…I use iPad to reply the message so it looks like strange.

1 Like

its fine, thank you, it worked for me

1 Like

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