@5uphi, I tried your method but I still can’t I’ll show you my scripts
--PlayerData (ServerScriptService)
local Players = game:GetService("Players")
local DataStoreModule = require(game.ServerStorage.DataStore)
local Red = require(game.ReplicatedStorage.Red)
local remoteEvent = Red.Server("AllEvent")
local template = {
--[[
IN LEADERSTATS
]]
Wins = 0,
--[[
IN OTHER
]]
Grade = "Beginer",
StoreCoins = 0,
Codes = {}
}
local function StateChanged(state, dataStore, player)
while dataStore.State == false do
if dataStore:Open(template) ~= "Success" then
task.wait(6)
end
end
end
Players.PlayerAdded:Connect(function(player)
local dataStore = DataStoreModule.new("Player", player.UserId)
dataStore.StateChanged:Connect(StateChanged)
StateChanged(dataStore.State, dataStore, player)
end)
Players.PlayerRemoving:Connect(function(player)
local dataStore = DataStoreModule.find("Player", player.UserId)
if dataStore ~= nil then
dataStore:Destroy()
end
end)
--the script you sent me (ServerScriptService)
local DataStoreModule = require(game.ServerStorage.DataStore)
local Red = require(game.ReplicatedStorage.Red)
local remoteEvent = Red.Server("AllEvent")
local function Set(dataStore, name, value)
if dataStore.State ~= true then return false end
dataStore.Value[name] = value
remoteEvent:Fire(dataStore.Player, name, value)
return name
end
local function Increment(dataStore, name, delta)
if dataStore.State ~= true then return false end
dataStore.Value[name] += delta
remoteEvent:Fire(dataStore.Player, name, dataStore.Value[name])
return true
end
game.Players.PlayerAdded:Connect(function(player)
local dataStore = DataStoreModule.new("Player", player.UserId)
dataStore.Player = player
dataStore.Set = Set
dataStore.Increment = Increment
end)
-- Custom Function (ServerScriptService)
local DataStoreModule = require(game.ServerStorage.DataStore)
game.Players.PlayerAdded:Connect(function(player)
local dataStore = DataStoreModule.new("Player", player.UserId)
local state = dataStore.StateChanged:Wait()
if state ~= true then return end
local success = dataStore:Set("Grade", dataStore.Value.Grade)
local success = dataStore:Increment("Codes", dataStore.Value.Codes)
end)
--ManageCode (ReplicatedStorage
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local player = game.Players.LocalPlayer
local Red = require(ReplicatedStorage.Red)
local rewardModule = require(ReplicatedStorage.InformationModule)
local remoteEvent = Red.Client("AllEvent")
local codeFrame = player.PlayerGui.CenterGui.CodeFrame.InfoFrame
local code = {}
code.__index = code
function code.new(text: string?, storeCoins: number?, Expired)
local newCode = {}
setmetatable(newCode, code)
newCode.Code = text
newCode.StoreCoins = storeCoins
newCode.Expired = Expired
newCode.Redeem = false
return newCode
end
function code:CodeEnter(codesValue)
if self.Expired == true then
rewardModule:cloneVotingText(codeFrame, "This code Expired")
else
if table.find(codesValue, self.Code) then
rewardModule:cloneVotingText(codeFrame, "Code already Redeem")
else
remoteEvent:Fire("codeRedeem", self.Code, self.StoreCoins)
rewardModule:cloneVotingText(codeFrame, "Code Redeem")
end
end
end
return code
--MainScript (Client)
--CodeFrame:
remoteEvent:On("Codes", function(codesValue)
enterCode.FocusLost:Connect(function()
local code = orderedCode[enterCode.Text]
if code then
code:CodeEnter(codesValue)
else
informationModule:cloneVotingText(codeGui, "This Code Doesnt exist")
end
end)
end)