Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Cannot store Instance in data store. Data stores can only accept valid UTF-8 characters.?

Cannot store Instance in data store. Data stores can only accept valid UTF-8 characters. second script:

local ds = game:GetService("DataStoreService"):GetDataStore("Data")

game.Players.PlayerAdded:Connect(function(plr)
	local key = plr.UserId.."_id"
	local save = plr.stats.ins
	
	local savel = ds:GetAsync(key)
	if savel then
		save.Value = savel[1]
	else
		local nfs = {save}
		ds:GetAsync(key, nfs)
	end
end)

game.Players.PlayerRemoving:Connect(function(plr)
	local key = plr.UserId.."_id"
	local save = plr.stats.ins
	ds:SetAsync(key, save)
end)

first script:

game.Players.PlayerAdded:Connect(function(plr)
	local folder = Instance.new("Folder", plr)
	folder.Name = "stats"
	
	local ins = Instance.new("NumberValue", folder)
	ins.Name = "ins"
	ins.Value = 1
end)

1 comment

0

You are trying to save an instance, "save" which is ins whatever that is.. You can only save userdata values, not objects itself

2 answers

✓ Accepted answer

Second script:

local ds = game:GetService("DataStoreService"):GetDataStore("Data")

game.Players.PlayerAdded:Connect(function(plr)
    local key = plr.UserId.."_id"
    local save = plr.stats.ins

    local savel = ds:GetAsync(key)
    if savel then
        save.Value = savel[1]
    else
        local nfs = {save}
        ds:GetAsync(key, nfs)
    end
end)

game.Players.PlayerRemoving:Connect(function(plr)
    local key = plr.UserId.."_id"
    local save = plr.stats.ins.Value
    ds:SetAsync(key, save)
end)

Fixed :D

1 comment

0

iHavoc101 not working :(

This discussion is preserved as it was. New answers, comments, and votes are closed.