If always calls false even though conditions are met

I’m making a system that blocks players who have a certain value set in a leaderstats DataStore from using certain functions of my game. The problem is, that even though the conditions to unblock the player are met, the script blocks the player from doing that specific action anyway.

Here’s what the DataStore variables are defined as:

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Wait() --Wait for the player to load
	leaderstats = Instance.new("Folder") --Creates a new folder for the player
	leaderstats.Name = "leaderstats" --Sets Folder name to "leaderstats" --MAKE SURE YOU DON'T CHANGE THIS
	leaderstats.Parent = player --Puts the Folder under the player

	local blocked = Instance.new("IntValue") --Creates an IntValue
	blocked.Name = "Blocked" --Sets IntValue name to "Points" (If you change this make sure you change all of them)
	blocked.Parent = leaderstats --Puts the IntValue under the "leaderstats" folder
	blocked.Value = "0" --Gives the IntValue Value to start off with

	local data = nil --Data is empty

	local success, errorMessage = pcall(function() 
		data = dataStore:GetAsync(player.UserId) --Finds the player's UserId and data
	end)

	if success and data then --If UserId and Data found then
		blocked.Value = data[1] --Sets points to the first set of data
	else --If UserId or Data not found then
		print("Player has no data.") --Player has no data
		warn(errorMessage)
	end
end)

And here’s what the block part itself looks like:

if rejected[textInput] == nil and leaderstats.Blocked.Value == "0" then
	print("went through")
	print(leaderstats.Blocked.Value)
	print(rejected[textInput])
	local dcData = {
		['embeds'] = {{
			['title'] = textInput,
			['description'] = "A new submission has been made: **"..textInput.."**",
			['color'] = tonumber(0xF57D34)
			}
		}
	}
	local finalData = http:JSONEncode(dcData)
	http:PostAsync(hook,finalData)
else
	print("didn't go through")
	print(leaderstats.Blocked.Value)
	print(rejected[textInput])
end

However, this is what I’m getting:
image

Can anyone tell me how to fix this?

1 Like

does this work with int values?

1 Like

You were actually right before you deleted the post. :sob:

It turns out the problem was that I was trying to make the value a string because it had been causing me some problems earlier, when it was supposed to be a number. Thanks!

deleted it because i thought i was stupid when i saw where you defined it but then realized it was an int value :sweat_smile:

1 Like

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