Hi,
I've managed to find a script that saves leaderboard values, made by Crazyman32 (So I assume it works? My game doesn't use leaderstats, it's hard to test)
Would anyone be able to indicate how I'd change it to saving specific values (Values saved within the PlayerGui) I'm afraid I've tried much to no avail. I'm very willing to do it myself, I'm willing to learn, so I really just need pointers on how to go about it.
function DataHandler(p,o,key) -- DataHandler(Player, Object [, Key])
local types = {
IntValue = "Number";
NumberValue = "Number";
ObjectValue = "Instance";
BoolValue = "Boolean";
StringValue="String";
}
local t = types[o.ClassName]
if (not t) then return end
key = (type(key) == "string" and key or o.Name) -- If it's a string, keep it the same, ELSE change it to the object's name. Allows 'key' to be an optional argument.
key = (#key > 0 and key or key.Name == o.Name and o.ClassName or o.Name) -- If length of string is greater than 0, keep it the same
if (not p.DataReady) then -- ELSE if it is equal to the object's name then that means that the
p:WaitForDataReady() -- object's name is blank, therefore make 'key' the ClassName.
end -- ELSE make it the name of the object.
local Save,Load = p[("Save%s"):format(t)],p[("Load%s"):format(t)] -- Steal the load and save functions from the player
o.Value = Load(p,key) -- The same as p:LoadTYPE(key). Since it's no longer a method, the player must be the first argument
local lastV = o.Value
o.Changed:connect(function(v)
lastV = v
Delay(1,function() -- Give a 1 second buffer to see if the value changes anymore. If so, stop the operation. If it goes 1 second without changing, it will automatically save.
if (lastV ~= v) then return end -- This way you don't save a value 20 times in 1 second if it changes constantly. Lower data processing = less lag
Save(p,key,v)
end)
end)
end
--[[
-- Example:
game.Players.PlayerAdded:connect(function(player)
local l = Instance.new("IntValue",player)
l.Name = "leaderstats"
local money = Instance.new("IntValue",l)
money.Name = "Money"
DataHandler(player,money,"TheMoney")
end)
]]
ANY help is greatly appreciated, thanks all. |