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

2 Likes

Like this?
Twitter Codes System | HowTo Resource | Scripting - Resources / Community Tutorials - DevForum | Roblox
Edit: also, scripting support is for existing scripts.

2 Likes

I appriciate your help but no, What i want to do is that in chat you put for example !code Sin
and then it gives idk umm, 50 stats points…

No GUI’s

2 Likes

How can I make a !Code #### Command in chat - Help and Feedback / Scripting Support - DevForum | Roblox
I think this would work.

2 Likes

I think you are looking for the Player.Chatted event.

A simple example of this could be

    game.Players.PlayerAdded:Connect(function(player)
      player.Chatted:Connect(function(msg)
            if msg == string.lower("!code sin") then
                -- do stuff with msg and player
            end
      end)
    end)

Obviously, you could make a more complex type check that uses !Code as a prefix etc., but this should work in a simplistic example.

Also, using string.lower will make sure that the code isn’t case sensitive. Cheers!

1 Like

how can i make it so they can only redeem it once?

I think, changing it to something like this:

 game.Players.PlayerAdded:Connect(function(player)
x=0
      player.Chatted:Connect(function(msg)
            if msg == string.lower("!code sin") and x == 0 then
x=1
                -- do stuff with msg and player
            end
      end)
    end)

Let me try… That Real quick

Big problem when i leave the game it doesnt save so i can keep doing the code

Uh, well I guess you could make it a boolvalue and put it in a datastore.

1 Like

Can u help me with that i am prettty new to scripting :confused:

Well, you need to make usage of a DataStore to save that they have redeemed it.
If you don’t care if it saves or not, then you can use the above example from @ShadowAlien98.

    local pointsDataStore = game:GetService("DataStoreService"):GetDataStore("Points")
     
    game.Players.PlayerAdded:Connect(function(player)
    	local playerKey = "Player_" .. player.UserId
    	-- Give 50 points to players each time they visit
    	local success, err = pcall(function()
    		pointsDataStore:UpdateAsync(playerKey, function(oldValue)
    			local newValue = oldValue or 0
    			newValue = newValue + 50
    			return newValue
    		end)
    	end)
    end)

This is an example of how to save something to a DataStore (found on the wiki)

Thats saving the data by every 50 points so if they dont get 50 points by the time they leave they would have nothing

(This is an example of tables)
Datastore Tutorial for Beginners - Resources / Community Tutorials - DevForum | Roblox
Wait…or is it dictionaries…

The code bit here tries to save.

local success, err = pcall(function()
	pointsDataStore:UpdateAsync(playerKey, function(oldValue)
		local newValue = oldValue or 0
		newValue = newValue + 50
		return newValue
	end)

It calls the pointsDataStore:UpdateAsync() function, but it has the argument of oldValue (which is the saved value in the DataStore), by default this is nil or non-existent.

local newValue = oldValue or 0
newValue = newValue + 50
return newValue

In this section, newValue is defined as the old value (could be nil and if it is, it will be set to 0). Then it increments whatever their oldValue is by 50.

So in layman terms, if you join with no data: it will do [0 + 50] else [your value + 50] so it just adds 50 to your current saved value.

Ohh so either way its gonna save no matter what your “POINTS” are ?

Correct, so in your case you could just save a boolean value (true or false) whether or not they have redeemed the code or not.

Ok but thats saving the points in general… i want it to save like the if you said that in chat like !code sin << example then you wont be able to get a reward for saying that twice or infinite times.

i just saw ur chat

The code:

 game.Players.PlayerAdded:Connect(function(player)
code = player.code
      player.Chatted:Connect(function(msg)
            if msg == string.lower("!code sin") and code.Value == false then
code.Value = true
                -- do stuff with msg and player
            end
      end)
    end)