Problem With ProfileService

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

There isnt exactly a lot of info about your problem.

Dont just expect people to understand it by thowing a large amount of code without guidance.

1 Like

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.

I think I see the issue, you are adding the Player argument into FireServer for the ModCode Event , you dont need to do this as it will already be specified as a Player Instance in the script, try removing it

Like that, right?

ModCode.OnServerEvent:Connect(function(player: Player, inputCode: string)
	Manager.ModifyCode(inputCode)
end)

This piece of code, to this:

button.MouseButton1Click:Connect(function()
		ModCode:FireServer(inputCode)
	end)

I misread what you said, sorry.

Still nothing. Nothing changed tbh.

Should I undo the other one? Or keep it the same?

Yeah, undo it, i misread what you said.

Still nothing changed. Hm. I did undo too.

Hey, I remade everything and almost everything works. When I say almost, I mean that only the Invalid condition works.

Server Script:

local ProfileCasher = require(script.Parent.ProfileCasher)

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ModCode = ReplicatedStorage.Remotes.ModCode
local SendCode = ReplicatedStorage.Remotes.SendCode

ModCode.OnServerEvent:Connect(function(player, inputCode)
	local playerProfile = ProfileCasher[player]
	
	for index, value in pairs(playerProfile.Data.Codes) do
		print(index, value)
		if index == inputCode then
			print("Found Code")
			if not value.Expired then
				if not value.Redeemed then
					print("Redeemed")
					SendCode:FireClient(player, "Success")
					value.Redeemed = true
				elseif value.Redeemed then
					print("Already Redeemed")
					SendCode:FireClient(player, "AlreadyRedeemed")
				end
			elseif value.Expired then
				print("Expired")
				SendCode:FireClient(player, "Expired")
			end
		elseif index ~= inputCode then
			print("Invalid")
			SendCode:FireClient(player, "Invalid")
		end
	end
end)

CodeManager:

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(inputCode)
	end)
	
	SendCode.OnClientEvent:Connect(function(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

ProfileCasher:

local Players = game:GetService("Players")
local cashedProfiles = {}
local ProfileService = require(script.ProfileService)

local saveStructure = {
	Codes = {
		["RELEASE"] = {
			Expired = false;
			Redeemed = false;
		};
	};
}

local PlayerProfileStore = ProfileService.GetProfileStore("PlayerData", saveStructure)

local function playerAdded(player)
	local profile = PlayerProfileStore:LoadProfileAsync("Player_"..player.UserId, "ForceLoad")
	
	if profile ~= nil then
		profile:ListenToRelease(function()
			cashedProfiles[player] = nil
			player:Kick("Your profile has been loaded remotely, Please rejoin.")
		end)
		
		if player:IsDescendantOf(Players) then
			cashedProfiles[player] = profile
			-- Loaded
		else
			profile:Release()
		end
	else
		player:Kick("Unable to load saved data. Please rejoin.")
	end
end

for _, player in ipairs(Players:GetPlayers()) do
	spawn(function()
		playerAdded(player)
	end)
end

Players.PlayerAdded:Connect(playerAdded)
Players.PlayerRemoving:Connect(function(player)
	local profile = cashedProfiles[player]
	if profile ~= nil then
		profile:Release()
	end
end)

return cashedProfiles

So when I press the button, the output is:
image

I Fixed it, the problem had to do with the Code Manager and the textbox.

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