I have some values for my game that check weather you’ve bought something or not and i set up data saves for them but I also have a system that changes your character to a different rig and when it switches your character the game thinks that the values are all false meaning you lose all the stuff you bought.
the values are duplicated between the ui and the player’s backpack and playerscripts and if the ui scripts change the backpack values and the playerscripts values change and it all works fine until the character changes then all the values all switch to their base values as if you just started the game (only the shop items).
what im wondering is if when the player’s character changes does it reset all the stuff on the playerscripts, backpack, and playergui? and if so how do i fix this
When your thing flips, all the stuff inside forgets itself. To keep it, you gotta hide it somewhere that sticks and bring it back when the new thing shows.
Yes, I’m being vague on purpose. I like to match the question. ![]()
what im wondering is if when the player’s character changes does it reset all the stuff on the playerscripts, backpack, and playergui? and if so how do i fix this
yes. to fix store your values somewhere else, like underneath the player instance
PlayerScripts, no, these are cloned from StarterPlayerScripts to under your Player once when you join the server, and not replaced when you respawn your character.
Anything in StarterCharacterScripts is re-cloned every time your character respawns.
Backpack is rebuilt from StarterPack when you respawn.
PlayerGui is more complicated. It is also repopulated fro StarterGui on respawn, but Gui containers (ScreenGui, SurfaceGui, etc.) will not be overwritten (re-cloned) if their “ResetOnSpawn” property is false (unchecked) on the copy in StarterGui, at authoring time.
It’s not advised to change ResetOnSpawn at runtime, especially not on the copy cloned under your PlayerGui, as this can result in duplicate copies of the whole gui being active. Children of a gui container that has ResetOnSpawn = false at authoring time, even children added at runtime to the cloned copy, will persist. If ResetOnSpawn = true, they will not.
You still having problems.. my bad.
Store persistent values outside the character.. use Player instance properties..
Could use BoolValue, IntValue etc. under Player
Your scripts should reference the Player instance, not the Character instance..
Use Player.CharacterAdded to reapply tools and values.
Kind of a mock up here, because you gave me nothing to work with:
local Players = game:GetService("Players")
local ServerStorage = game:GetService("ServerStorage")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local shopEvent = ReplicatedStorage:WaitForChild("ShopEvent")
shopEvent.OnServerEvent:Connect(function(player, itemName)
local flag = player:FindFirstChild("Own_"..itemName) or Instance.new("BoolValue")
if not flag.Parent then
flag.Name = "Own_"..itemName
flag.Parent = player
end
flag.Value = true
local tool = ServerStorage:FindFirstChild(itemName)
if tool then
tool:Clone().Parent = player.Backpack
end
shopEvent:FireClient(player, "Bought", itemName)
end)
Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function()
for _,v in pairs(player:GetChildren()) do
if v:IsA("BoolValue") and v.Name:sub(1,4) == "Own_" and v.Value then
local tool = ServerStorage:FindFirstChild(v.Name:sub(5))
if tool then
tool:Clone().Parent = player.Backpack
end
end
end
task.wait()
shopEvent:FireClient(player, "Resync")
end)
end)
I solved this, i just had the datastores constantly set values based on your saved data so that when you respawn it keeps your values as they were before, then when the values are changed in game such as buying a character it sets your datastore values.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.