How to change a gui's text using value:changed after creating it with a module script That needs another module

Thanks for reading,
Okay I Know title is confusing. but I will try my best to explain in a good way
so I am trying to update gui everytime a player’s value changed

--This is a local script to send value and fire ValueChanged function
LocalPlayer.leaderstats.Strength.Changed:Connect(function(Wakanda)
AchivementModuleV2.ValueChanged("Strength",LocalPlayer.leaderstats.Strength.Value)
	print(Wakanda)
end)

but I am consufed about how to reach the module that hold rewards,names etc just for that spesific Value’s part and update it because Value.Changed event only sends the newValue and I think I can’t just do it with sending “Strength” or “Coins” because I can’t use the max valuable since ı want the Value/max to stay there

like if it is strength value then I just want it use variables of totalStrength1 or 2
if sended value is 10 then for totalStrength 1 it should Change text to 10/20(max)
or for totalStrength2 it should Change text to 10/67890

local module = {
	{ID = "TotalCoins1",Level= 1,Max = 100,Reward = "%10+Coins",Image = "rbxassetid://9310206048",},
	{ID = "TotalStrength1",Level = 1,Max = 20,Reward= "%10+PowerPerSwing",Image = "rbxassetid://9310206048"},
--	{ID = "TotalSwingTime1",Level = 1,Max = 10,Reward= "FasterSwing",Image = "rbxassetid://9310206048"},
	{ID = "TotalCoins2",Level= 2,Max = 56789,Reward = "%10+Coins",Image = "rbxassetid://12583460061"},
	{ID = "TotalStrength2",Level = 2,Max = 67890,Reward= "%10+PowerPerSwing",Image = "rbxassetid://12583460061"},
	--{ID = "TotalSwingTime2",Level = 2,Max = 100,Reward= "FasterSwing",Image = "rbxassetid://12583460061"}
}
return module
-- This is a module script
local ClickedItem
local MainFrame = script.Parent:WaitForChild("Frame")
local AchivementModule = require(game:GetService("ReplicatedStorage"):WaitForChild("Achivements"))
local LocalPlayer = game:GetService("Players").LocalPlayer
local Template = script:WaitForChild("Template")
local ScrollingFrame = MainFrame:WaitForChild("Frame"):WaitForChild("ScrollingFrame")
local InfoFrame = MainFrame:WaitForChild("InfoFrame")
local InfoGoing = InfoFrame:WaitForChild("Going")
local InfoTakeIt = InfoFrame:WaitForChild("TakeIt")
local InfoReward = InfoFrame:WaitForChild("Reward")
local InfoFrameFrame = InfoFrame:WaitForChild("Frame")
local InfoProgressBar = InfoFrame:WaitForChild("ProgressBar")

local AchivementRemotes = game:GetService("ReplicatedStorage"):WaitForChild("Remotes"):WaitForChild("AchivementModules")
local ClickedAchivements
local Achivement = {}


Achivement.__index = Achivement



local function ShowInfos(Visible)
	InfoGoing.Visible = Visible
	InfoReward.Visible = Visible
	InfoTakeIt.Visible = Visible
	InfoFrameFrame.Visible = Visible
end
function Achivement:ValueChanged(Number)
print("I am KindaBored") 
	print(Number)
	if InfoReward.Text:find("Power") then
      InfoGoing.Text = Number
		
		
	end
end

function Achivement:Santarantiano() -- function to create buttons
	print("TESTSTUFF")
	ShowInfos(false)
	print(AchivementModule)
	for i, v in ipairs(AchivementModule) do
		local object = setmetatable({},Achivement)
	
		object.Name = if v.ID then v.ID else nil
		object.Image = if v.Image then v.Image else nil
		object.Level = if  v.Level then v.Level else nil
		object.Max = if  v.Max then v.Max else nil
		object.Reward = if v.Reward then v.Reward else nil
		

		local TemplateClone = Template:Clone()
		TemplateClone.Name = v.ID
		TemplateClone.Parent = ScrollingFrame
		TemplateClone.Visible = true
		TemplateClone:WaitForChild("AchivementImage").Image = v.Image
		TemplateClone.Activated:Connect(function()
			print(object)
			Achivement:OnClick(object)
			print("ButtonTouched")
			print(v)
		end)
		object.ClaimButton = InfoTakeIt
		if v.Level == 1 then
			TemplateClone.BackgroundColor3 = Color3.fromRGB(40, 65, 223)
		elseif v.Level == 2 then
			TemplateClone.BackgroundColor3 = Color3.fromRGB(209, 102, 223)
		end
	end
end
return Achivement

this is how it looks in game after client activated one of the buttons


(Don’t mind the shenhe pictures they are just random picture Id’s I found in toolbox)

Run the program in the studio and go track down where the text is at that you want to change. Once you know that it should be easy to add that location to your change script.

It’s should be in: Players.PlayerName.PlayersGui.GuiName

I don’t want to sound mean or rude but it is already there

As far as I understand, you want to connect values to Change event on client side so whenerver the value changes it gets data from a client module.
Check this example:

This ServerScript is only to show the values Im adding into player:
Im adding 4 values, Power, Power2, Coins, Coins2

local function ValuesMaker(name, val, target)
	local newVal = Instance.new("IntValue")
	newVal.Name = name
	newVal.Value = val
	newVal.Parent = target
end

game.Players.PlayerAdded:Connect(function(plr)
	local newFold = Instance.new("Folder")
	newFold.Name = "leaderstats"
	newFold.Parent = plr
	
	ValuesMaker("Power", 0, newFold)
	ValuesMaker("Power2", 0, newFold)
	ValuesMaker("Coins", 0, newFold)
	ValuesMaker("Coins2", 0, newFold)
end)

Then this is how the client module looks in player:

local module = {
	["Power"] = {Max = 100, Reward = "%10+Power", Image = "rbxassetid://9310206048"},
	["Power2"] = {Max = 20, Reward = "%10+Power2", Image = "rbxassetid://9310206048"},
	["Coins"] = {Max = 50, Reward = "%10+Coins", Image = "rbxassetid://9310206048"},
	["Coins2"] = {Max = 200, Reward = "%10+Coins2", Image = "rbxassetid://9310206048"},
}
return module

Then this is the client script which is in the ScreenGui. Its grabbing all values in leaderstats by using a loop and connecting the Change event to them to print some of the data in output.
Im just grabbing “Max” key, you can take any of the keys as you need. Lastly the print/warn is formatted to show something like “Power: 5/50”

local player = game.Players.LocalPlayer

local module = require(player:WaitForChild("PlayerScripts"):WaitForChild("ModuleScript")) -- I suppose is a client module in player
local leaderstats = player:WaitForChild("leaderstats")

for _, value in pairs(leaderstats:GetChildren()) do
	value.Changed:Connect(function(val)
		
		--warn(value.Name, ":", val) -- The name of the value changed along with the new value
		warn(("%s: %s/%s"):format(value.Name, val, module[value.Name]["Max"])) -- Get the data from module and format it
		
		-- Now just access your GUI elements to edit them depending on the name of the value
		
	end)
end
2 Likes

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