How can i make a code system like the video below?

Ohhh ok well u guys have a good night i really like u guys can yall add my discord its

daniiel.perrez#3260

I have to go to sleep i have districts tomorrow

1 Like

Night, also don’t forget to mark a comment as the answer.

Very glad to help! Thank you for helping as well, @ShadowAlien98!

Before I go, what would be an example as a value inside of the datastore, for your script?
Edit: nvm I was just being dumb and mispelling it lol

1 Like

Thanks for sharing my plugin :slight_smile:

1 Like

NP, good things should be shared.

2 Likes

Hey shadow i forgot to ask a long time ago and now is when i need it how can i add more codes?

Trayeus how can i add more codes?

Give me a few mins and ill tell u.

Adding onto his code system script thingy (should work)

local codesDataStore = game:GetService("DataStoreService"):GetDataStore("Codes")

function saveRedeemed(playerKey, code)
	local redeemed = false
	local firstTime = false
	local success, err = pcall(function()
		codesDataStore:UpdateAsync(playerKey .. "_" .. code, function(oldValue)
			local newValue = oldValue or false
			if newValue == false then
				newValue = true -- new save value
				redeemed = true
				firstTime = true
			end
			return newValue
		end)
	end)
	if not success then -- fail safe
		redeemed = true
	end
	return redeemed, firstTime
end

game.Players.PlayerAdded:Connect(function(player)

	local playerKey = "Player_" .. player.UserId

	local stats = Instance.new("Folder", workspace)
	stats.Name = player.Name .. "_stats"

	local code = Instance.new("BoolValue", stats)
	code.Name = "code"

	local codeb = Instance.new("BoolValue", stats) --add more of this and the line below changing the codeb parts to different things
	codeb.Name = "codeb"

	player.Chatted:Connect(function(msg)
		if msg == string.lower("!code sin") then
			local redeemed, firstTime = saveRedeemed(playerKey, "sin")
			code.Value = redeemed
			if firstTime ~= nil and firstTime == true then
				-- give them the reward (will save 1 time only)
				player.leaderstats.Bucks.Value = player.leaderstats.Bucks.Value + 100
			end
		elseif msg == string.lower("!code sin2") and codeb.Value == false then --change the text inside of string lower, and copy from that line to the --//end comment
			local redeemed, firstTime = saveRedeemed(playerKey, "sin2")  --change sin2 to the code
			codeb.Value = redeemed --change codeb to the code in the instance.new part
			if firstTime ~= nil and firstTime == true then
				-- give them the reward (will save 1 time only)
				player.leaderstats.Bucks.Value = player.leaderstats.Bucks.Value + 10000
			end  --//end
		end
	end)
end)

can u show me an example. ill like that

Just did what I added with the comments.

local codesDataStore = game:GetService("DataStoreService"):GetDataStore("Codes")

function saveRedeemed(playerKey, code)
	local redeemed = false
	local firstTime = false
	local success, err = pcall(function()
		codesDataStore:UpdateAsync(playerKey .. "_" .. code, function(oldValue)
			local newValue = oldValue or false
			if newValue == false then
				newValue = true -- new save value
				redeemed = true
				firstTime = true
			end
			return newValue
		end)
	end)
	if not success then -- fail safe
		redeemed = true
	end
	return redeemed, firstTime
end

game.Players.PlayerAdded:Connect(function(player)

	local playerKey = "Player_" .. player.UserId

	local stats = Instance.new("Folder", workspace)
	stats.Name = player.Name .. "_stats"

	local code = Instance.new("BoolValue", stats)
	code.Name = "code"
	local code = Instance.new("BoolValue", stats)
	code.Name = "code"
	local codeb = Instance.new("BoolValue", stats) --add more of this and the line below changing the codeb parts to different things
	codeb.Name = "codeb"
	local codec = Instance.new("BoolValue", stats) 
	codec.Name = "codec"

	player.Chatted:Connect(function(msg)
		if msg == string.lower("!code sin") then
			local redeemed, firstTime = saveRedeemed(playerKey, "sin")
			code.Value = redeemed
			if firstTime ~= nil and firstTime == true then
				-- give them the reward (will save 1 time only)
				player.leaderstats.Bucks.Value = player.leaderstats.Bucks.Value + 100
			end
		elseif msg == string.lower("!code sin2") and codeb.Value == false then --change the text inside of string lower, and copy from that line to the --//end comment
			local redeemed, firstTime = saveRedeemed(playerKey, "sin2")  --change sin2 to the code
			codeb.Value = redeemed --change codeb to the code in the instance.new part
			if firstTime ~= nil and firstTime == true then
				-- give them the reward (will save 1 time only)
				player.leaderstats.Bucks.Value = player.leaderstats.Bucks.Value + 10000
			end  --//end
		elseif msg == string.lower("!code sin3") and codec.Value == false then --change the text inside of string lower, and copy from that line to the --//end comment
			local redeemed, firstTime = saveRedeemed(playerKey, "sin3")  --change sin2 to the code
			codeb.Value = redeemed --change codec to the code in the instance.new part
			if firstTime ~= nil and firstTime == true then
				-- give them the reward (will save 1 time only)
				player.leaderstats.Bucks.Value = player.leaderstats.Bucks.Value + 1000000
			end  --//end
		end
	end)
end)