Int Value on Text Label Issue

My int value changed script is not working. I’ve placed this script in the workspace and it is a server script. (I’m not sure where to put it so…)

Goal: The int value goes up every second, so the text label should show the player’s second count

GUI script:

local intValue = game.ServerStorage.Counts.Value
local textLabel = game.StarterGui.ScreenGui.TextLabel

intValue.Changed:Connect(function()
	textLabel.Text = tostring(intValue.Value)
end)

Other scripts (everything is in one script, this part is working)

local counts = game.ServerStorage.Counts
local part = game.Workspace.IntValueTest
-- counter
coroutine.wrap(function()
	while true do
		counts.Value = counts.Value + 1
		wait(1)
	end
end)()

-- event
part.Touched:Connect(function(hit)
	print("you have been playing for", counts.Value, "seconds")
end)

thank you so much in advance! i really appreciate it :smiley:

Try it in ReplicatedStorage, ServerStorage is only for the server and the client will not ever see it.

And are there any errors?

2 Likes

As mentioned above, you can not access ServerStorage from the client.

local Replicated = game:GetService("ReplicatedStorage")
local intValue = Replicated:WaitForChild("Counts")

local textLabel = script.Parent.ScreenGui.TextLabel -- your path to that label from the script.

intValue.Changed:Connect(function()
	textLabel.Text = tostring(intValue.Value)
end)

I also noticed:
You defined intValue as the Value itself.
And inside the Changed event you try to set the text into the Value of the value. Which wont work.
Try what I sent above.

2 Likes

gotcha, thank you so much for the clarification! and nope!

Thank you so much! Should I place the script in replicated storage as well, or can I keep it in the workspace? :smiley:

try this:

local intValue = game.ServerStorage.Counts.Value
local textLabel = game.StarterGui.ScreenGui.TextLabel

intValue.Changed:Connect(function(amount)
	textLabel.Text = amount
end)
1 Like