Hi everyone, I’m trying to change the Value in the GUI(The script is located under the text, where the player should be shown the amount of value he currently has, and I’m using ProfileService). but for some reason, I’m getting the error “StatsFolder is not a valid member of Player” in a local script inside the text. How to fix it? I would be grateful for any help. Here are the scripts:
local Players = game:GetService("Players")
local ServerScriptService = game:GetService("ServerScriptService")
local Template = require(script.Parent:WaitForChild("Template"))
local ProfileService = require(ServerScriptService.Libs:WaitForChild("ProfileService"))
local Manager = require(script.Parent:WaitForChild("Manager"))
local ProfileStore = ProfileService.GetProfileStore("DataAllSaves", Template)
local function Statsa(player: Player)
local profile = Manager.Profiles[player]
if not profile then return end
local StatsFolder = Instance.new("Folder", player)
StatsFolder.Name = "StatsFolder"
local StageCoinsValue = Instance.new("IntValue", StatsFolder)
StageCoinsValue.Name = "StageCoinsValue"
StageCoinsValue.Value = profile.Data.StageCoinsValue
local DonationValue = Instance.new("IntValue", StatsFolder)
DonationValue.Name = "DonationValue"
DonationValue.Value = profile.Data.DonationValue
end
local function PlayerAdded(player: Player)
local Profile = ProfileStore:LoadProfileAsync("Player_"..player.UserId)
if Profile == nil then
player:Kick("Error data, join again.")
return
end
Profile:AddUserId(player.UserId)
Profile:Reconcile()
Profile:ListenToRelease(function()
Manager.Profiles[player] = nil
player:Kick("Error data, join again.")
end)
if player:IsDescendantOf(Players) == true then
Manager.Profiles[player] = Profile
Statsa(player)
else
Profile:Release()
end
end
for _, player in ipairs(Players:GetPlayers()) do
task.spawn(PlayerAdded, player)
end
Players.PlayerAdded:Connect(PlayerAdded)
Players.PlayerRemoving:Connect(function(player: Player)
local profile = Manager.Profiles[player]
if not profile then return end
profile:Release()
end)
This is ProfileService script. FromServerScriptService.
local Event = game.ReplicatedStorage.StageCoinChange
local Players = game:GetService("Players")
local ServerScriptService = game:GetService("ServerScriptService")
local PlayerData = require(ServerScriptService.PlayerData:WaitForChild("Manager"))
Event.OnServerEvent:Connect(function()
for _, player in Players:GetPlayers() do
local profile = PlayerData.Profiles[player]
if not profile then return end
profile.Data.StageCoinsValue += 1
player.StatsFolder.StageCoinsValue.Value += 1
print(profile.Data.StageCoinsValue)
end
end)
This script adds value with remote event. From ServerScriptService.
local event = game.ReplicatedStorage.StageCoinChange
task.wait(6)
while task.wait(1) do
event:FireServer()
end
This is LocalScript from StarterCharacterScripts. it just adds value to the player on the server.
local CoinStageText = script.Parent
local Player = game.Players.LocalPlayer
local function ChangedValue()
CoinStageText.Text = "StageCoin: "..Player.StatsFolder.StageCoinsValue.Value
end
Player.StatsFolder.StageCoinsValue.Changed:Connect(ChangedValue)
and here is the script that causes that same error (on line 11). The script is below the text.