Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How would I sync this overhead gui script with leaderstats?

i have NO clue how to put this into a well-formed question title i'm so sorry

okay, so i'm trying to do overhead gui ranks for a sim game i'm doing (no it is NOT about stick eating at all), and i've been trying to get it to sync with a certain leaderstats value.

the code looks like this:

script.Parent = game.ServerScriptService
local billboard = script.BillboardGui
function zigzag(X) return math.acos(math.cos(X*math.pi))/math.pi end
counter = 0

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(char)
		if player.leaderstats.Cronches.Value >= 0 then
			local newgui = billboard:Clone()
			newgui.Parent = char.Head
			newgui.TextLabel.TextColor3 = Color3.fromRGB(255,255,255)
			newgui.TextLabel.Text = "New Croncher"
		elseif player.leaderstats.Cronches.Value >= 10000 then
			local newgui = billboard:Clone()
			newgui.Parent = char.Head
			newgui.TextLabel.TextColor3 = Color3.fromRGB(136,93,46)
			newgui.TextLabel.Text = "Bronze Croncher"
		elseif player.leaderstats.Cronches.Value >= 100000 then
			local newgui = billboard:Clone()
			newgui.Parent = char.Head
			newgui.TextLabel.TextColor3 = Color3.fromRGB(211,211,211)
			newgui.TextLabel.Text = "Silver Croncher"	
		elseif player.leaderstats.Cronches.Value >= 1000000 then
			local newgui = billboard:Clone()
			newgui.Parent = char.Head
			newgui.TextLabel.TextColor3 = Color3.fromRGB(255,255,0)
			newgui.TextLabel.Text = "Gold Croncher"	
		elseif player.leaderstats.Cronches.Value >= 10000000 then
			local newgui = billboard:Clone()
			newgui.Parent = char.Head
			newgui.TextLabel.TextColor3 = Color3.fromRGB(0,221,255)
			newgui.TextLabel.Text = "Diamond Croncher"	
		elseif player.leaderstats.Cronches.Value >= 100000000 then
			local newgui = billboard:Clone()
			newgui.Parent = char.Head
			newgui.TextLabel.TextColor3 = Color3.fromRGB(147,147,147)
			newgui.TextLabel.Text = "Platinum Croncher"	
		elseif player.leaderstats.Cronches.Value >= 1000000000 then
			local newgui = billboard:Clone()
			newgui.Parent = char.Head
			newgui.TextLabel.TextColor3 = Color3.fromRGB(255,170,0)
			newgui.TextLabel.Text = "Expert Croncher"	
		elseif player.leaderstats.Cronches.Value >= 10000000000 then
			local newgui = billboard:Clone()
			newgui.Parent = char.Head
			newgui.TextLabel.TextColor3 = Color3.fromRGB(255,109,0)
			newgui.TextLabel.Text = "Croncher Extraordinaire"
		elseif player.leaderstats.Cronches.Value >= 100000000000 then
			local newgui = billboard:Clone()
			newgui.Parent = char.Head
			newgui.TextLabel.TextColor3 = Color3.fromRGB(255,0,0)
			newgui.TextLabel.Text = "Superior Croncher"	
		elseif player.leaderstats.Cronches.Value >= 1000000000000 then
			local newgui = billboard:Clone()
			newgui.Parent = char.Head
			while wait(0.1)do
			newgui.TextLabel.TextColor3 = Color3.fromHSV(zigzag(counter),1,1)
			 counter = counter + 0.01
			end
			newgui.TextLabel.Text = "The Absolute Croncher"				
			
		end
	end)
end)

Cronches is the leaderstat value i'm wanting to track, the zigzag function atop is just for being a part of the color of the final title to be color-changing

it sorta works, the issue being it doesn't go past the 1st title of new croncher, and i'm wondering what i can do to get past my issue of the text not changing according to the leaderstats value of a player changing

maybe i'm missing a part where i should add LocalPlayer somewhere into this, i am not sure

if anyone can guide me as to a way to fix this and/or guide me to a way as to make a more efficient script instead of this that'd be kind. thank you. i hope i explained enough and i hope this doesn't sound like a request

2 comments

0

are you getting any errors in the output or is there none?

0

i'm not getting any errors in the output for this

2 answers

✓ Accepted answer

I believe the reason for this is because the script is only checking the value once. So you should use GetPropertyChangedSignal which will fire when a value is changed, learn more about it here So there fixed code should be:

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(char)
		local leaderstats = player:WaitForChild("leaderstats") -- Wait for player stats
		local Cronches = leaderstats:WaitForChild("Cronches")
		Cronches:GetPropertyChangedSignal("Value"):Connect(function() -- Fires when the player Cronches value changes
			if Cronches.Value >= 0 then
				-- Do something
			elseif Cronches.Value >= 10000 then
				-- Do something, etc...
			end
		end)
	end)
end)

Hope this helps and if it did, remember to accept! If there is an error, report it and I will fix is asap!

Your script is always sayings its >= 0 because its always above 0, you should do if player.leaderstats.Cronches.Value >= 0 and player.leaderstats.Cronches.Value <= 9999 then for the first one and then if player.leaderstats.Cronches.Value >= 10000 and player.leaderstats.Cronches.Value <= 99999 then for the second one. and so on. (you find the next rank and subtract 1 and then put it as and player.leaderstats.Cronches.Value <= thatnumberhere)

1 comment

0

tried that, didn't affect anything and still doesn't go past the first title :(

This discussion is preserved as it was. New answers, comments, and votes are closed.