I am trying to create a Code System that saves using the ProfileService, but when I enter the code in the UI, nothing happens. I have attempted to debug using print statements in various scripts, but have not been successful. Specifically, I attempted to debug the ModifyCode function but it did not work. I believe the issue may be with the “ModCode” remote event.
Let me show you the scripts first.
Manager Module:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Remotes = ReplicatedStorage.Remotes
local SendCode = Remotes.SendCode
local module = {}
module.Profiles = {}
function module.ModifyCode(player: Player, inputCode: string)
local profile = module.Profiles[player]
if not profile then return end
print("hi")
for i, v in pairs(profile.Data.Codes) do
print("hi")
if v == inputCode then
if not v.Expired then
if not v.Redeemed then
SendCode:FireClient(player, "Success")
print("success")
v.Redeemed = true
elseif v.Redeemed then
SendCode:FireClient(player, "AlreadyRedeemed")
print("already redeemed")
end
elseif v.Expired then
SendCode:FireClient(player, "Expired")
print("expired")
end
elseif v ~= inputCode then
SendCode:FireClient(player, "Invalid")
print("Invalid")
end
end
end
return module
Template Module:
local Codes = {
["RELEASE"] = {
Redeemed = false;
Expired = false;
}
}
local module = {
Codes = Codes;
}
return module
CodeManager Module:
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Remotes = ReplicatedStorage.Remotes
local ModCode = Remotes.ModCode
local SendCode = Remotes.SendCode
local CodeManager = {}
CodeManager._index = CodeManager
function CodeManager.new(player: Player, inputCode: TextBox, rewardText: TextLabel, button: TextButton)
local self = setmetatable({}, CodeManager)
self.RewardText = rewardText
button.MouseButton1Click:Connect(function()
ModCode:FireServer(player, inputCode)
end)
SendCode.OnClientEvent:Connect(function(player, status)
print("send code")
if status == "Success" then
-- Release Code
if inputCode == "RELEASE" then
self.RewardText.Text = "TIMESKIP (TEST)"
wait(1)
self.RewardText.Text = "N/A"
end
elseif status == "Invalid" then
self.RewardText.Text = "INVALID"
wait(1)
self.RewardText.Text = "N/A"
elseif status == "Expired" then
self.RewardText.Text = "EXPIRED"
wait(1)
self.RewardText.Text = "N/A"
elseif status == "AlreadyRedeemed" then
self.RewardText.Text = "ALREADY REDEEMED"
wait(1)
self.RewardText.Text = "N/A"
end
end)
return self
end
return CodeManager
Server Script:
local Manager = require(script.Parent.Manager)
local ProfileService = require(script.Parent.Parent.Libs.ProfileService)
local Template = require(script.Parent.Template)
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Remotes = ReplicatedStorage.Remotes
local ModCode = Remotes.ModCode
local ProfileStore = ProfileService.GetProfileStore("Production", Template)
local function PlayerAdded(player: Player)
local profile = ProfileStore:LoadProfileAsync("Player_"..player.UserId)
if profile == nil then
player:Kick("Data issue, try again shortly. If issue persists, contact us!")
return
end
profile:AddUserId(player.UserId)
profile:Reconcile()
profile:ListenToRelease(function()
Manager.Profiles[profile] = profile
end)
end
ModCode.OnServerEvent:Connect(function(player: Player, inputCode: string)
Manager.ModifyCode(player, inputCode)
end)
Players.PlayerAdded:Connect(PlayerAdded)
Now let me tell you the paths.
Manager Module → ServerScriptService > Data (Folder)
Template Module → ServerScriptService > Data (Folder)
Server Script → ServerScriptService > Data (Folder)
CodeManager Module → ReplicatedStorage > Libs (Folder)
I hope you reach out to me and help fix my problem