StringValue not changing on the server side, while also changing

Hey, recently I bumped into this bug while working on my Job system.
It checks when an event was fired, then changes the value through a ServerScript, which works, but then it doesn’t, and I am unsure why, it does change on the ServerSide, but the scripts don’t seem to recognize it. Thank you in advance.

ClientSide

game.ReplicatedStorage.Events.Assigment:FireServer(x.Text, valn)

ServerSide, the value changer

game.ReplicatedStorage.Events.Assigment.OnServerEvent:Connect(function(plr, job, NPC)
	NPC.GInformation.Job.Value = job
	print("changed to "..job)
end)

ServerSide, the value checker (x represents NPC’s model)

			if SmthToDo == false and Wander.Value == false and x.GInformation.Task.Value == false then
				if SmthToDo == false then
					local j = workspace.Map.NPCs[x.Name].GInformation.Job.Value
					if j ~= "" then
						print(j)
					end
					warn(j)
--Works up until here
					if j == "Woodworker" then
						print("Working")

But the code, or description doesn’t clear it up well, so here are a couple of screenshots:
image

I have no idea why is this happening, I have already tried to tamper with the code, by looking for the value again, which is the state you can see it now, but it is still not working.

Looks like j value is empty, in output you got only how many times script outputed the empty string. That’s why also it does not print j because it not passes j ~= "".

I also have a request for you. Start naming things in the script instead of single letters, it will make things easier for everyone.

I am very aware of that, that bit is to print if it is not an empty string, if you look into the last screenshot, you can see that the string is, in fact, not empty, and has the value that is required to print “Working”

So I decided to try storing the data in the script itself, but it still does not work
image

for i,x in pairs(workspace.Map.NPCs:GetChildren()) do
	coroutine.wrap(function()
		print("loading "..x.Name)
		local anim = script.Animate:Clone()
		anim.Parent = x
		anim.Enabled = true
		local Finishedyet = false
		local SmthToDo = false
		local j = ""
			if SmthToDo == false and Wander.Value == false and x.GInformation.Task.Value == false then
				if SmthToDo == false then
					print(j)
					if j == "Woodworker" then
						print("Working")
				x.GInformation.Job.Changed:Connect(function(val)
					warn(x.Name.."is now a "..val)
					j = val
				end)

Would you mind if you send the entire value checker code? Right now I feel like the variables don’t make sense, not knowing where they are located, how else they are handled, etc.

Sure, here;

for i,x in pairs(workspace.Map.NPCs:GetChildren()) do
	coroutine.wrap(function()
		print("loading "..x.Name)
		local anim = script.Animate:Clone()
		anim.Parent = x
		anim.Enabled = true
		local Finishedyet = false
		local SmthToDo = false
		local j = ""
		local funcfin = Instance.new("BoolValue", a)
		funcfin.Name = x.Name.."funcfin"
		local p = sp.new(x)
		local Wander = Instance.new("BoolValue", a)
		Wander.Name = x.Name.."wander"
		for i = 1,12 do
			local a = x.GInformation.Skills:GetChildren()[math.random(1,#x.GInformation.Skills:GetChildren())]
			a.Value +=1
		end
		x.GInformation.Status.Age.Value = math.random(19,24)
		local a = x.GInformation.Traits:GetChildren()[math.random(1,#x.GInformation.Traits:GetChildren())]
		a.Value = true
		while true do
			wait(.2)
			local stgs = workspace.Map.SandboxSettings
			x.GInformation.Status.Fun.Value -=.05*stgs.FunRate.Value
			x.GInformation.Status.Hunger.Value -=.0025*stgs.HungerRate.Value
			x.GInformation.Status.Thirst.Value -=.005*stgs.ThirstRate.Value
			if x.GInformation.Traits.Insomniac.Value == false then
				if game.Lighting:GetMinutesAfterMidnight() > 18*60 then
					x.GInformation.Status.Energy.Value -=.2*stgs.EnergyRate.Value
				end
			else
				if game.Lighting:GetMinutesAfterMidnight() <6*60 then
					x.GInformation.Status.Energy.Value -=.2*stgs.EnergyRate.Value
				end
			end
			if SmthToDo == false and Wander.Value == false and x.GInformation.Task.Value == false then
				if SmthToDo == false then
					print(j)
					if j == "Woodworker" then
						print("Working")
						local Con_A, Con_B
						if not workspace.Map.Zones.Woodwork.CanCollide then
							Con_A = workspace.Map.Zones.Woodwork.Touched:Connect(function () end)
						end
						--(repeat for PartB, using variable Con_B)
						local TouchingParts = workspace.Map.Zones.Woodwork:GetTouchingParts()
						local Touching = false
						for Index, Other in pairs(TouchingParts) do
							if Other == workspace.Map.Zones.Woodwork then
								Touching = true
								break
							end
						end
						if Con_A then Con_A:Disconnect() end
						if Con_B then Con_B:Disconnect() end
						for i, z in pairs(TouchingParts) do
							print(z)
							if z:FindFirstChild("Chop") and SmthToDo == false then
								SmthToDo = true
								x.GInformation.Task.Value = true
								local obj = z:FindFirstAncestorOfClass("Model")
								if x.GInformation.Inv:FindFirstChild("Axe") then
									obj.PrimaryPart.Chop.Used.Value = true
								end
								p:Run(obj.PrimaryPart.Pos.WorldPosition)
								p.Reached:Connect(function()
									if x.GInformation.Inv:FindFirstChild("Axe") then
										local axe = x.GInformation.Inv.Axe.Value:Clone()
										axe.Handle.PickUp:Destroy()
										axe.Handle.Fall.PlayOnRemove = true
										axe.Parent = x
										local M6 = Instance.new("Motor6D", x.HumanoidRootPart)
										M6.Part0 = x.HumanoidRootPart
										M6.Part1 = axe.PrimaryPart
										coroutine.wrap(function()
											tws:Create(x.HumanoidRootPart, TweenInfo.new(1, Enum.EasingStyle.Back, Enum.EasingDirection.Out), {CFrame = CFrame.lookAt(x.HumanoidRootPart.Position, Vector3.new(obj.PrimaryPart.Position.X, x.HumanoidRootPart.Position.Y , obj.PrimaryPart.Position.Z))}):Play()
										end)
										local num = ((math.random(6380,7490)*obj.PrimaryPart.Chop.RankHigherThan.Value)*10/(x.GInformation.Status.Energy.Value*(x.GInformation.Status.Energy.Value*.1)))/2.7
										local a = x.Humanoid:LoadAnimation(axe.Use)
										a:Play()
										axe.Handle.Chop:Play()
										wait(num)
										axe.Handle.Chop:Stop()
										a:Stop()
										for i, x in pairs(obj.PrimaryPart.Chop.Output:GetChildren()) do
											local num = math.random(x.Min.Value, x.Max.Value)
											for i = 1, num do
												local model = x.Value:Clone()
												model.Parent = workspace.Map.Interactables
												model.PrimaryPart.Position = obj.PrimaryPart.Position
											end
										end
										axe:Destroy()
										M6:Destroy()
										obj:Destroy()
										x.GInformation.Task.Value = false
										SmthToDo = false
									else
										local popup = script.InfPopup:Clone()
										popup.Parent = x
										dsv:AddItem(popup, 2)
										popup.Frame.InfMain.Text = x.Name.." doesn't have an axe"
										tws:Create(popup, TweenInfo.new(2), {ExtentsOffsetWorldSpace = Vector3.new(0,2,0)}):Play()
										for i, x in pairs(popup:GetDescendants()) do
											if x:IsA("TextLabel") then
												tws:Create(x, TweenInfo.new(2), {TextTransparency = 1, TextStrokeTransparency = 1}):Play()
											end
										end
										popup.Frame.InfBack.Text = popup.Frame.InfMain.Text
										x.GInformation.Task.Value = false
										SmthToDo = false
									end
								end)
							end
						end
					end
				end
			end
			if x.GInformation.Task.Value == false then
				if x.GInformation.Status.Energy.Value <=50 then
					local food = updateTarget(x, "Sleep")
					if food ~= nil and food.Sleep.Value == false then
						food.Sleep.Used.Value = true
						SmthToDo = true
						p:Run(food.Position)
						p.Reached:Connect(function()
							Finishedyet = true
							x.GInformation.Task.Value = true
							print("sleep")
							repeat wait(.1)
								x.GInformation.Status.Energy.Value +=.2*stgs.EnergyRate.Value*3
							until x.GInformation.Status.Energy.Value >=80
							x.GInformation.Task.Value = false
							food.Sleep.Used.Value = false
							SmthToDo = false
						end)
					end
				end
				if x.GInformation.Status.Energy.Value <=10 then
					local food = updateTarget(x, "Sleep")
					if food == nil then
						SmthToDo = true
						Finishedyet = true
						x.GInformation.Task.Value = true
						print("Pass out")
						repeat wait(.1)
							x.GInformation.Status.Energy.Value +=.2*stgs.EnergyRate.Value*3
						until x.GInformation.Status.Energy.Value >=80
						x.GInformation.Task.Value = false
						SmthToDo = false
					end
				end
				if x.GInformation.Status.Hunger.Value <=70 then
					local GotFood = false
					for i, z in pairs(x.GInformation.Inv:GetChildren()) do
						if z:IsA("ObjectValue") then
							if z.Value.PrimaryPart:FindFirstChild("Eat") then
								GotFood = true
								wait(3)
								x.GInformation.Status.Hunger.Value += z.Value.PrimaryPart.Eat.Nutrition.Value
								z:Destroy()
							end
						end
					end
					if GotFood == false then
						local food = updateTarget(x, "Eat")
						if food ~= nil then
							SmthToDo = true
							p:Run(food.Position)
							p.Reached:Connect(function()
								food.Drink.BeingUsed.Value = false
								Finishedyet = true
								local Model = game.ReplicatedStorage.Objects:FindFirstChild(food.Eat.Model.Value):Clone()
								Model.Parent = x.HumanoidRootPart
								Model.CFrame = x.Humanoid.RootPart.CFrame
								dsv:AddItem(Model, 3)
								local Amount = food.Eat.Nutrition.Value
								food:FindFirstAncestorOfClass("Model"):Destroy()
								wait(3)
								x.GInformation.Status.Hunger.Value += Amount
								x.GInformation.Task.Value = false
								food.Eat.BeingUsed.Value = false
								SmthToDo = false
							end)
						end
					end
				end
				x.GInformation.Job.Changed:Connect(function(val)
					warn(x.Name.."is now a "..val)
					j = val
				end)
				if x.GInformation.Status.Thirst.Value <=70 then
					local GotFood = false
					for i, z in pairs(x.GInformation.Inv:GetChildren()) do
						if z:IsA("ObjectValue") then
							if z.Value.PrimaryPart:FindFirstChild("Drink") then
								GotFood = true
								wait(3)
								x.GInformation.Status.Hunger.Value += z.Value.PrimaryPart.Eat.Nutrition.Value
								z:Destroy()
							end
						end
					end
					if GotFood == false then
						local food = updateTarget(x, "Drink")
						if food ~= nil then
							SmthToDo = true
							p:Run(food.Position)
							p.Reached:Connect(function()
								food.Drink.BeingUsed.Value = true
								Finishedyet = true
								local Model = game.ReplicatedStorage.Objects:FindFirstChild(food.Drink.Model.Value):Clone()
								Model.Parent = x.HumanoidRootPart
								Model.CFrame = x.Humanoid.RootPart.CFrame
								dsv:AddItem(Model, 3)
								local Amount = food.Drink.Nutrition.Value
								food:FindFirstAncestorOfClass("Model"):Destroy()
								wait(3)
								x.GInformation.Status.Thirst.Value += Amount
								x.GInformation.Task.Value = false
								food.Drink.BeingUsed.Value = false
								SmthToDo = false
							end)
						end
					end
				end
				if x.GInformation.Status.Fun.Value <=70 then
					print("Bored")
					local NPC = updateTargetNPC(x, "NPC", "Player", "Friendly")
					if NPC ~= nil then
						SmthToDo = true
						p:Run(NPC.InteractionPos.WorldCFrame.Position)
						p.Reached:Connect(function()
						end
					end
				end
			end
		end
	end)()
end

I might be wrong, but you never changed the j variable in the script, so it just thinks its “” probably. Make sure to change it when you change the string value

If that doesnt work, then you need to get the job value again when checking the value. Just do another variable like j2 and then the string value again. That way it gets the new version.

Can’t seem to figure out why this happens, but it probably wouldn’t matter anyway:

I doubt the variable is useful, since essentially you’re using the value of Job. Just directly access Job.Value.


Some code review

By the way, the code is heavily nested, and a lot of lines are extremely long, which makes it harder to read (especially when the code is revisited after a long while, or someone else is reading it). There’s also a lot of single-letter names, which are meaningless when read as they don’t describe what they are holding.

For single-letter variables, please name them properly (e.g. if x is for the NPC, name it descriptively, such as npcModel)
For the long lines, you can simply store objects into another variable (e.g. x.GInformation.Skills → local npcSkills = x.GInformation.Skills`)

For extreme nesting, this video might help (by CodeAesthetic):
Why You Shouldn't Nest Your Code - YouTube

Also,

1 Like

I did do that on the first run, and it did not work, hence I tried different methods, like turning it into a variable, which didn’t work as well, as you can see. And about code nesting and stuff, I am planning to essentially rework the entirety of code later on, improve performance and all that, this is just a “proof of concept”, I guess you could call it; just getting the very base to work in whatever way, see if it is fun to play with, if so, then redo it to be more effective, you get the drill.

After some more tampering with it, I figured that if I change the value before running it, it does work, just as intended and previously tested, but then again it recognizes it as nil, but it does work. But on the other hand, I cannot really use that as I want it to be changed in real-time.
image

After further tampering, I noticed that it works, but only if the value is set from Explorer, which is lame because a script does that already, but it just does not recognize it.

There were a lot of specifics that weren’t explained buuut my best guess would be that the NPC you’re sending through the RemoteEvent is an Instance and something about the testing/network conditions doesn’t like that

Try just sending a reference to the desired NPC instead (ex: a name that you can search for) and follow that reference until you can change the value you want to change, and make sure that the NetworkOwner of the NPC is set to the Server (I’m unsure of whether or not that actually has an effect on it, but it’s nice to rule out possible variables)

Then, if that reference method does work, then you know the problem lies in the Networking of the project and not necessarily your method/logic

1 Like

Yep, that is how it works, and I did do that in most ways of getting the variable, by searching for the NPC, and then the value again. I just now did also try out the network ownership, and it still does not work.

this connection is hidden under this ‘if statement’

if x.GInformation.Task.Value == false then

it could be that the if statement fails and function to change j is never connected. I think it should be connected outside the while loop, try putting it right under where you declare j

1 Like

Unsure if I understood you correctly (if I didn’t, then my apologies), but if you look at when I did gameplay tests and stuff, it does get through that if statement, and in the more recent version of the code, which I’ll put down, I also tried to get rid of the function entirely, as it is quite unnecessary, and it can be easily avoided

local a = Instance.new("Folder", script)
a.Name = "NPCs"
for i,x in pairs(workspace.Map.NPCs:GetChildren()) do
	coroutine.wrap(function()
		print("loading "..x.Name)
		local anim = script.Animate:Clone()
		anim.Parent = x
		anim.Enabled = true
		local Finishedyet = false
		local SmthToDo = false
		local funcfin = Instance.new("BoolValue", a)
		funcfin.Name = x.Name.."funcfin"
		local jobval = Instance.new("StringValue", a)
		jobval.Name = x.Name.."jobval"
		local p = sp.new(x)
		local Wander = Instance.new("BoolValue", a)
		Wander.Name = x.Name.."wander"
		for i = 1,12 do
			local a = x.GInformation.Skills:GetChildren()[math.random(1,#x.GInformation.Skills:GetChildren())]
			a.Value +=1
		end
		x.GInformation.Status.Age.Value = math.random(19,24)
		local a = x.GInformation.Traits:GetChildren()[math.random(1,#x.GInformation.Traits:GetChildren())]
		a.Value = true
		--Main
		while true do
			wait(.2)
			local stgs = workspace.Map.SandboxSettings
			x.GInformation.Status.Fun.Value -=.05*stgs.FunRate.Value
			x.GInformation.Status.Hunger.Value -=.0025*stgs.HungerRate.Value
			x.GInformation.Status.Thirst.Value -=.005*stgs.ThirstRate.Value
			if x.GInformation.Traits.Insomniac.Value == false then
				if game.Lighting:GetMinutesAfterMidnight() > 18*60 then
					x.GInformation.Status.Energy.Value -=.2*stgs.EnergyRate.Value
				end
			else
				if game.Lighting:GetMinutesAfterMidnight() <6*60 then
					x.GInformation.Status.Energy.Value -=.2*stgs.EnergyRate.Value
				end
			end
			if SmthToDo == false and Wander.Value == false and x.GInformation.Task.Value == false then
				print(jobval.Value)
				if jobval.Value == "Woodworker" then
					print("Working")
					local Con_A, Con_B
					if not workspace.Map.Zones.Woodwork.CanCollide then
						Con_A = workspace.Map.Zones.Woodwork.Touched:Connect(function () end)
					end
					--(repeat for PartB, using variable Con_B)
					local TouchingParts = workspace.Map.Zones.Woodwork:GetTouchingParts()
					local Touching = false
					for Index, Other in pairs(TouchingParts) do
						if Other == workspace.Map.Zones.Woodwork then
							Touching = true
							break
						end
					end
					if Con_A then Con_A:Disconnect() end
					if Con_B then Con_B:Disconnect() end
					for i, z in pairs(TouchingParts) do
						print(z)
						if z:FindFirstChild("Chop") and SmthToDo == false then
							SmthToDo = true
							x.GInformation.Task.Value = true
							local obj = z:FindFirstAncestorOfClass("Model")
							if x.GInformation.Inv:FindFirstChild("Axe") then
								obj.PrimaryPart.Chop.Used.Value = true
							end
							p:Run(obj.PrimaryPart.Pos.WorldPosition)
							--Pathfind(NPC, place.WorldPosition)
							p.Reached:Connect(function()
								if x.GInformation.Inv:FindFirstChild("Axe") then
									local axe = x.GInformation.Inv.Axe.Value:Clone()
									axe.Handle.PickUp:Destroy()
									axe.Handle.Fall.PlayOnRemove = true
									axe.Parent = x
									local M6 = Instance.new("Motor6D", x.HumanoidRootPart)
									M6.Part0 = x.HumanoidRootPart
									M6.Part1 = axe.PrimaryPart
									coroutine.wrap(function()
										tws:Create(x.HumanoidRootPart, TweenInfo.new(1, Enum.EasingStyle.Back, Enum.EasingDirection.Out), {CFrame = CFrame.lookAt(x.HumanoidRootPart.Position, Vector3.new(obj.PrimaryPart.Position.X, x.HumanoidRootPart.Position.Y , obj.PrimaryPart.Position.Z))}):Play()
									end)
									local num = ((math.random(6380,7490)*obj.PrimaryPart.Chop.RankHigherThan.Value)*10/(x.GInformation.Status.Energy.Value*(x.GInformation.Status.Energy.Value*.1)))/2.7
									local a = x.Humanoid:LoadAnimation(axe.Use)
									a:Play()
									axe.Handle.Chop:Play()
									wait(num)
									axe.Handle.Chop:Stop()
									a:Stop()
									for i, x in pairs(obj.PrimaryPart.Chop.Output:GetChildren()) do
										local num = math.random(x.Min.Value, x.Max.Value)
										for i = 1, num do
											local model = x.Value:Clone()
											model.Parent = workspace.Map.Interactables
											model.PrimaryPart.Position = obj.PrimaryPart.Position
										end
									end
									axe:Destroy()
									M6:Destroy()
									obj:Destroy()
									x.GInformation.Task.Value = false
									SmthToDo = false
								else
									local popup = script.InfPopup:Clone()
									popup.Parent = x
									dsv:AddItem(popup, 2)
									popup.Frame.InfMain.Text = x.Name.." doesn't have an axe"
									tws:Create(popup, TweenInfo.new(2), {ExtentsOffsetWorldSpace = Vector3.new(0,2,0)}):Play()
									for i, x in pairs(popup:GetDescendants()) do
										if x:IsA("TextLabel") then
											tws:Create(x, TweenInfo.new(2), {TextTransparency = 1, TextStrokeTransparency = 1}):Play()
										end
									end
									popup.Frame.InfBack.Text = popup.Frame.InfMain.Text
									x.GInformation.Task.Value = false
									SmthToDo = false
								end
							end)
						end
					end
				end
					--[[
					Wander.Value = true
					p:Run(x.HumanoidRootPart.Position+Vector3.new(math.random(-10,10),0, math.random(-10,10)), true)
					p.Reached:Connect(function()
						wait(math.random(3,5))
						Wander.Value = false
					end)--]]
			end
			if x.GInformation.Task.Value == false then
				if x.GInformation.Status.Energy.Value <=50 then
					local food = updateTarget(x, "Sleep")
					if food ~= nil and food.Sleep.Value == false then
						food.Sleep.Used.Value = true
						SmthToDo = true
						p:Run(food.Position)
						p.Reached:Connect(function()
							Finishedyet = true
							x.GInformation.Task.Value = true
							print("sleep")
							repeat wait(.1)
								x.GInformation.Status.Energy.Value +=.2*stgs.EnergyRate.Value*3
							until x.GInformation.Status.Energy.Value >=80
							x.GInformation.Task.Value = false
							food.Sleep.Used.Value = false
							SmthToDo = false
						end)
					end
				end
				if x.GInformation.Status.Energy.Value <=10 then
					local food = updateTarget(x, "Sleep")
					if food == nil then
						SmthToDo = true
						Finishedyet = true
						x.GInformation.Task.Value = true
						print("Pass out")
						repeat wait(.1)
							x.GInformation.Status.Energy.Value +=.2*stgs.EnergyRate.Value*3
						until x.GInformation.Status.Energy.Value >=80
						x.GInformation.Task.Value = false
						SmthToDo = false
					end
				end
				if x.GInformation.Status.Hunger.Value <=70 then
					local GotFood = false
					for i, z in pairs(x.GInformation.Inv:GetChildren()) do
						if z:IsA("ObjectValue") then
							if z.Value.PrimaryPart:FindFirstChild("Eat") then
								GotFood = true
								wait(3)
								x.GInformation.Status.Hunger.Value += z.Value.PrimaryPart.Eat.Nutrition.Value
								z:Destroy()
							end
						end
					end
					if GotFood == false then
						local food = updateTarget(x, "Eat")
						if food ~= nil then
							SmthToDo = true
							p:Run(food.Position)
							p.Reached:Connect(function()
								food.Drink.BeingUsed.Value = false
								Finishedyet = true
								local Model = game.ReplicatedStorage.Objects:FindFirstChild(food.Eat.Model.Value):Clone()
								Model.Parent = x.HumanoidRootPart
								Model.CFrame = x.Humanoid.RootPart.CFrame
								dsv:AddItem(Model, 3)
								local Amount = food.Eat.Nutrition.Value
								food:FindFirstAncestorOfClass("Model"):Destroy()
								wait(3)
								x.GInformation.Status.Hunger.Value += Amount
								x.GInformation.Task.Value = false
								food.Eat.BeingUsed.Value = false
								SmthToDo = false
							end)
						end
					end
					--SearchForFood
				end
				--x.GInformation.Job.Changed:Connect(function(val)
				--	warn(x.Name.."is now a "..val)
				--	jobval.Value = val
				--end)
				if x.GInformation.Status.Thirst.Value <=70 then
					local GotFood = false
					for i, z in pairs(x.GInformation.Inv:GetChildren()) do
						if z:IsA("ObjectValue") then
							if z.Value.PrimaryPart:FindFirstChild("Drink") then
								GotFood = true
								wait(3)
								x.GInformation.Status.Hunger.Value += z.Value.PrimaryPart.Eat.Nutrition.Value
								z:Destroy()
							end
						end
					end
					if GotFood == false then
						local food = updateTarget(x, "Drink")
						if food ~= nil then
							SmthToDo = true
							p:Run(food.Position)
							p.Reached:Connect(function()
								food.Drink.BeingUsed.Value = true
								Finishedyet = true
								local Model = game.ReplicatedStorage.Objects:FindFirstChild(food.Drink.Model.Value):Clone()
								Model.Parent = x.HumanoidRootPart
								Model.CFrame = x.Humanoid.RootPart.CFrame
								dsv:AddItem(Model, 3)
								local Amount = food.Drink.Nutrition.Value
								food:FindFirstAncestorOfClass("Model"):Destroy()
								wait(3)
								x.GInformation.Status.Thirst.Value += Amount
								x.GInformation.Task.Value = false
								food.Drink.BeingUsed.Value = false
								SmthToDo = false
							end)
						end
					end
					--SearchForFood
				end
				if x.GInformation.Status.Fun.Value <=70 then
					print("Bored")
					local NPC = updateTargetNPC(x, "NPC", "Player", "Friendly")
					if NPC ~= nil then
						SmthToDo = true
						p:Run(NPC.InteractionPos.WorldCFrame.Position)
						p.Reached:Connect(function()
						end)
						--SearchForDrinks
					end
				end
			end
		end
	end)()
end
game.ReplicatedStorage.Events.Assigment.OnServerEvent:Connect(function(plr, job, NPC)
	NPC.GInformation.Job.Value = job
	script.NPCs[NPC.Name.."jobval"].Value = job
	print("changed to "..job)
end)

Is this version working any better? Can you show the console

1 Like

Nope, still the same, no errors, output going normal, not printing out the

like how it should be supposed to, were it to work,
image

Put a print statement at the top of the while loop so we can see if the script is recognizing the updated value at all:

while true do
    wait(.2)
    print(jobval.Value)
    ...
end
1 Like

Thank you! Doing this helped me figure out where and why was it not working, I overlooked the fact that opening the UI set task value to be true. Thank you!

1 Like

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