If-then statements with values

So basically I’m making a game where you have to collect 3 crystals to close up a portal, every time you collect a crystal a value will go up by 1 (string value). The script to close up the portal is disabled by default. What im trying to do is, when the StringValue.Value reaches 3 ,the script for the portal will be disabled false. When the value is below 3 the script will stay disabled until the player finds the 3 crystals.

The problem is that it just doesnt work at all, the script stays disabled no matter what, i am a complete noob in scripting so i obviously must’ve made a crucial mistake. Anyways here’s the script:

local Status = game.ReplicatedStorage.DisplayValues.Status

game:GetService(“Players”).PlayerAdded:Connect(function(Player)
if Status.Value == 3 then
script.Parent.Disabled = false
elseif Status.Value ~= 3 then
script.Parent.Disabled = true
end
end)

(DisplayValues is a folder, status is the name of the stringvalue and the script shown here is a child of the script that closes the portal)

i have seen something on the dev forum with tables, but I couldn’t get it to work either. I dont even know if im using the right value for this :grimacing:

Firstly why are you using string values for number values? You can use an int value or number value, as what im thinking here is that the script is trying to compare a string value and a number value which doesn’t work. In order to use strings as numbers when comparing youll need to use the “tonumber()” function (Basically converts strings to numbers).

Please put your code into blocks also, hope this helps!

1 Like

You said that the status value is a type of string… That means u would need to check for “3” as string and not 3 as a number

1 Like

thx, i changed it to a numbervalue and it works now :smiley: im rlly new to values, this is literally the first time i ever used values in a script, anyways, thanks for clearing this up :slight_smile:

1 Like