StringValue not updating

So I Have the below script and I have another script that changes the Value of Difficulty depending on the users wishes I know that the value changes because I have gone into the players “Player” and seen that it does change. The script below is part of a larger script but this part only starts once the Value of Difficulty has changed I dont know what is whrong with it but it just wont pick up the updated value of Difficulty. The humand part is the humanoid of a player.

Players
-My Player
–Folder
—Difficulty

File Structure Above and Script Below

	`Difficulty = (game.Players:GetPlayerFromCharacter(human.Parent)).Folder.Difficulty
	if Difficulty.Value == "Hard" then
		Difficulty = 3
	elseif Difficulty.Value == "Medium" then
		Difficulty = 2
	elseif Difficulty.Value == "Easy" then
		Difficulty = 1
    print(Difficulty.Value)`

Basically Originally Difficulty = nil then another script turns Difficulty to hard,medium or easy but this script only reads the first value nil not hard,medium or easy

1 Like

Could you show more of the code?

From what I currently see,
Try to put -

Difficulty.Value = 3 , and so for the 2 others

while true do
	local torso = findNearestTorso(bin.Position)
	if torso~=nil then
		Difficulty = (game.Players:GetPlayerFromCharacter(human.Parent)).Folder.Difficulty
		if Difficulty.Value == "Hard" then
			Difficulty = 3
		elseif Difficulty.Value == "Medium" then
			Difficulty = 2
		elseif Difficulty.Value == "Easy" then
			Difficulty = 1
		end
		print(Difficulty.Value)
		bin.BodyPosition.P = 10000*tonumber(Difficulty)
		moveTo(torso)
	elseif torso==nil then
		bin.BodyPosition.P = 0
	end
end

Try this:

while true do
	local torso = findNearestTorso(bin.Position)
	if torso~=nil then
		Difficulty = (game.Players:GetPlayerFromCharacter(human.Parent)).Folder.Difficulty
		if Difficulty.Value == "Hard" then
			Difficulty.Value = 3
		elseif Difficulty.Value == "Medium" then
			Difficulty.Value = 2
		elseif Difficulty.Value == "Easy" then
			Difficulty.Value = 1
		end
		print(Difficulty.Value)
		bin.BodyPosition.P = 10000*tonumber(Difficulty)
		moveTo(torso)
	elseif torso==nil then
		bin.BodyPosition.P = 0
	end
end
1 Like

I assume your Difficulty value is either a string or a number value, but in both cases, you’ll need to change its Value

what changed? ---------------(30 )

That part is fine for that i just want to change the local variable not global i just need help with the original value updating

I tested out this one, and seemed to be working fine, what errors are you getting?

attempt to perform arithmetic (mul) on number and nil
because when Difficuly*10000 The difficulty Value is not hard,medium or easy instead it is nil which it is originally because it doesnt read the updated value

Try this :

while true do
	local torso = findNearestTorso(bin.Position)
	if torso~=nil then
		Difficulty = (game.Players:GetPlayerFromCharacter(human.Parent)).Folder.Difficulty
		if Difficulty.Value == "Hard" then
			Difficulty.Value = 3
		elseif Difficulty.Value == "Medium" then
			Difficulty.Value = 2
		elseif Difficulty.Value == "Easy" then
			Difficulty.Value = 1
		end
		print(Difficulty.Value)
		bin.BodyPosition.P = 10000*tonumber(Difficulty.Value)
		moveTo(torso)
	elseif torso==nil then
		bin.BodyPosition.P = 0
	end
end

it should be like this

while true do
	local torso = findNearestTorso(bin.Position)
	if torso~=nil then
		Difficulty = (game.Players:GetPlayerFromCharacter(human.Parent)).Folder.Difficulty
		if Difficulty.Value == "Hard" then
			Difficulty.Value = "3"
		elseif Difficulty.Value == "Medium" then
			Difficulty.Value = "2"
		elseif Difficulty.Value == "Easy" then
			Difficulty.Value = "1"
		end
		print(Difficulty.Value)
		bin.BodyPosition.P = 10000*tonumber(Difficulty.Value)
		moveTo(torso)
	elseif torso==nil then
		bin.BodyPosition.P = 0
	end
end

Nope I get the same error as before. The thing that is wrong is that the value doesnt update the Difficulty = (game.Players:GetPlayerFromCharacter(human.Parent)).Folder.Difficulty part nothing else.

while true do
	local torso = findNearestTorso(bin.Position)
	if torso~=nil then
		Difficulty = (game.Players:GetPlayerFromCharacter(human.Parent)).Folder.Difficulty
		if Difficulty.Value == "Hard" then
			Difficulty.Value = "3"
		elseif Difficulty.Value == "Medium" then
			Difficulty.Value = "2"
		elseif Difficulty.Value == "Easy" then
			Difficulty.Value = "1"
		end
		print(Difficulty.Value)
		bin.BodyPosition.P = 10000*tonumber(Difficulty.Value)
		moveTo(torso)
	elseif torso==nil then
		bin.BodyPosition.P = 0
	end
end

try the one i send

while true do
	local torso = findNearestTorso(bin.Position)
	if torso~=nil then
		Difficulty = (game.Players:GetPlayerFromCharacter(human.Parent)).Folder.Difficulty
		if Difficulty.Value == "Hard" then
			Difficulty.Value = "3"
		elseif Difficulty.Value == "Medium" then
			Difficulty.Value = "2"
		elseif Difficulty.Value == "Easy" then
			Difficulty.Value = "1"
		end
		print(Difficulty.Value)
		bin.BodyPosition.P = 10000*tonumber(Difficulty.Value)
		moveTo(torso)
	elseif torso==nil then
		bin.BodyPosition.P = 0
	end
end

I thought you were talking about a Number Value, so I was confused.

1 Like

The thing that is wrong is that the value doesnt update the Difficulty = (game.Players:GetPlayerFromCharacter(human.Parent)).Folder.Difficulty part nothing else.

So any ideas???

So the string value isnt updating?
Also you’ve debugged it using print()
What output you got?

@Talls_Smols

1 Like

It is originally Nil until a person updates it to hard,medium,easy and i know that it updates to hard,medium,easy but this script only picks up the original value nil

When the person updates it then it still stays to nil?