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
game.Players.PlayerAdded:connect(function(player)
repeat wait() until player:WaitForChild("PlayerGui")
local testingRedeemed = Instance.new("BoolValue")
testingRedeemed.Value = false
testingRedeemed.Name = "testing"
testingRedeemed.Parent = player.PlayerGui["Twitter code"].Redeemed
local FiveKRedeemed = Instance.new("BoolValue")
FiveKRedeemed.Value = false
FiveKRedeemed.Name = "5k"
FiveKRedeemed.Parent = player.PlayerGui["Twitter code"].Redeemed
local OfcPedrooRedeemed = Instance.new("BoolValue")
OfcPedrooRedeemed.Value = false
OfcPedrooRedeemed.Name = "OfcPedroo"
OfcPedrooRedeemed.Parent = player.PlayerGui["Twitter code"].Redeemed
DataHandler(player,testingRedeemed,"testing")
DataHandler(player,FiveKRedeemed,"5k")
DataHandler(player,OfcPedrooRedeemed,"5k")
end)
COMMUNITY QUESTION
My twitter code datastore isn't working whats wrong with the script?
0 answers
No public answers were preserved for this question.
This discussion is preserved as it was. New answers, comments, and votes are closed.
