IntValue doesn't update globally?

I’m trying to check if an IntValue is bigger than a different IntValue

while wait(0.1) do

	local soul = script.Parent.Parent:WaitForChild("leaderstats").Soul
	local dirt = script.Parent.Parent:WaitForChild("vals").Dirt
	local req1 = script.Parent.Parent:WaitForChild("reqs").req1
	local dirtBtn = game.Workspace.dirtButton
	local holder = dirtBtn.GUI.text

	if soul.Value >= req1.Value then
		
		print(req1.Value)

		holder.TextColor3 = Color3.fromRGB(38, 255, 0)
	else
		holder.TextColor3 = Color3.fromRGB(38, 255, 0)

	end
end

It technally works, but in this script (localscript) the value is always 0 (the number assigned in the creation of the value). Therefor it is constantly the first colour because req1 is always 0 (so soul value is bigger) outside the script below.

In my other script (localscript) I change the value.

local holder = dirtBtn.GUI.text

local req1 = script.Parent.Parent:WaitForChild("reqs").req1.Value

req1 = 5 + (dirt.Value * 3)

holder.Text = req1.." Soul"

local ready = true

dirtBtn.Touched:Connect(function(hit,req1)
	
	req1 = 5 + (dirt.Value * 3)

	holder.Text = req1.." Soul"
	
	if soul.Value >= req1 then
	
		if ready == true then
		
			ready = false
		
			local char = game.Players.LocalPlayer.Character
		
			if hit.Parent == char then
				
				dirt.Value += 1
				dirtGui.Text = "Dirt: "..dirt.Value
				soul.Value -= req1
				soulGui.Text = "Soul: "..soul.Value
				
				wait(0.5)
				ready = true
				return req1
				
			end
		end
	end
end)

I though this was because it couldn’t communicate with the server, but here in my other script it updates the “Soul” value just fine.

while wait(SOULWAIT.Value) do
	soul.Value += 1 + dirt.Value
	soulGui.Text = "Soul: "..soul.Value
end

So I am asking why “req1” doesn’t update for my other scripts and stays on 0, but “Soul” updates just fine.

1 Like

just saying, u can use GetPropertyChangedSignal instead of loops

u shouldn’t be using loops when they are not needed

also, cool tip: u can use print to see where an issue is so its easier to fix or u can just re-write ur code

2 Likes

if I remember correctly, you have to do req1 = script.Parent.Parent:WaitForChild(“reqs”).req1
then do req1.Value instead of assigning the value to the variable, as if you assign it to the variable, the variable is just now an unchanging value and doesn’t point to the same location anymore

1 Like

I haven’t used that yet, but it’ll definetely help reduce lag when a game gets larger, so thank you for the reminder :slight_smile:

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