I am trying to make it so a server script can be run and change someone’s data globally through ProfileService, regardless of whether they are in-game or not.
The issue with this is that the profile you see me defining in the script constantly is registered as nil and kicks the player out of the game if they are in it.
I have looked for other fixes but can not find a way for this to work.
My script can be found below:
local ps = game:GetService("Players")
local Authorized = {"MoawesomeI8"}
local stringtofind ="/cmd"
ps.PlayerAdded:Connect(function(player)
if table.find(Authorized, player.Name) == nil then return end
player.Chatted:Connect(function(msg)
if string.find(msg, stringtofind) then
local ServerScriptService = game:GetService("ServerScriptService")
local Template = require(game.ServerScriptService.PlayerData.Template)
local ProfileService = require(ServerScriptService.Libs.ProfileService)
local Manager = require(game.ServerScriptService.PlayerData.Manager)
local ProfileStore = ProfileService.GetProfileStore("AllProfileData", Template)
local id = "Player_"..244071536
local profile = ProfileStore:LoadProfileAsync(id, "Steal")
if not profile then print("profile is not a profile") return end
profile:Reconcile()
ProfileStore:GlobalUpdateProfileAsync(
id,
function(global_updates)
global_updates:AddActiveUpdate({
Type = "CommunityBonus",
Item = "Gems",
Amount = 150,
})
end
)
profile:Save()
profile.GlobalUpdates:ListenToNewActiveUpdate(function(update_id, update_data)
profile.GlobalUpdates:LockActiveUpdate(update_id)
end)
profile.GlobalUpdates:ListenToNewLockedUpdate(function(update_id, update_data)
if update_data.Type == "CommunityBonus" and update_data.Item == "Gems" then
profile.Data.Gems += update_data.Amount
end
profile.GlobalUpdates:ClearLockedUpdate(update_id)
end)
profile:Release()
end
end)
end)
How do I go about making this work?