What do you want to achieve? Keep it simple and clear!
Hi, i want to save a value located inside of the player character, also if any can help me showing me a better method where should i locate the value or is it good inside of the player character
What is the issue? Include screenshots / videos if possible!
it doesnt really work since when u rejoin ur value its set to 0
What solutions have you tried so far? Did you look for solutions on the Creator Hub?
I saarched through the devforum but all of them were how to save leaderstats values and not other values
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
This is the code soo far
local plrs = game:GetService("Players")
local ds = game:GetService("DataStoreService")
local splatsave = ds:GetDataStore("splatsave")
plrs.PlayerAdded:Connect(function(plr)
local char = plr.Character or plr.CharacterAdded:Wait()
local splatsvalue = char:WaitForChild("SplatBucks_Value")
local plrid = plr.UserId
local data
local succes,fail = pcall(function()
data = splatsave:GetAsync(plrid)
end)
if succes then
splatsvalue.Value = data
else
error("User Currency Wasnt Loaded Succesfully")
end
end)
plrs.PlayerRemoving:Connect(function(plr)
local char = plr.Character or plr.CharacterAdded:Wait()
local splatsvalue = char:WaitForChild("SplatBucks_Value")
local plrid = plr.UserId
local succes,fail = pcall(function()
splatsave:SetAsync(splatsvalue.Value)
end)
end)
local plrs = game:GetService("Players")
local ds = game:GetService("DataStoreService")
local splatsave = ds:GetDataStore("splatsave")
plrs.PlayerAdded:Connect(function(plr)
local char = plr.Character or plr.CharacterAdded:Wait()
local splatsvalue = char:WaitForChild("SplatBucks_Value")
local plrid = plr.UserId
local data
local succes,fail = pcall(function()
data = splatsave:GetAsync(plrid)
end)
if succes then
splatsvalue.Value = data
else
error("User Currency Wasnt Loaded Succesfully")
end
end)
plrs.PlayerRemoving:Connect(function(plr)
local char = plr.Character or plr.CharacterAdded:Wait()
local splatsvalue = char:WaitForChild("SplatBucks_Value")
local plrid = plr.UserId
local succes,fail = pcall(splatsave.SetAsync,splatsave,plrid,splatsvalue.Value)
splatsave:SetAsync(plrid,splatsvalue.Value)
end)
local plrs = game:GetService("Players")
local ds = game:GetService("DataStoreService")
local splatsave = ds:GetDataStore("splatsave")
plrs.PlayerAdded:Connect(function(plr)
local splatsvalue = Instance.new("IntValue",plr)
splatsvalue.Name = "SplatBucks_Value"
local plrid = plr.UserId
local data
local succes,fail = pcall(function()
data = splatsave:GetAsync(splatsvalue)
end)
if succes then
splatsvalue.Value = data
else
error("User Currency Wasnt Loaded Succesfully")
end
end)
plrs.PlayerRemoving:Connect(function(plr)
local char = plr.Character or plr.CharacterAdded:Wait()
local splatsvalue = char:WaitForChild("SplatBucks_Value")
local plrid = plr.UserId
local succes,fail = pcall(splatsave.SetAsync,splatsave,plrid,splatsvalue.Value)
end)
Update, solved it by myself. Heres what my code looks like
local plrs = game:GetService("Players")
local ds = game:GetService("DataStoreService")
local splatsave = ds:GetDataStore("splat_save")
plrs.PlayerAdded:Connect(function(plr)
local datakey = plr.UserId.. "_splatsave"
local splats = Instance.new("IntValue",plr)
splats.Name = "SplatBucks_Value"
local success,fail = pcall(function()
return splatsave:GetAsync(datakey)
end)
if success then
if fail then
splats.Value = fail or 0
end
end
end)
plrs.PlayerRemoving:Connect(function(plr)
local datakey = plr.UserId.. "_splatsave"
local splats = plr:WaitForChild("SplatBucks_Value")
splatsave:SetAsync(
datakey,
splats.Value
)
end)