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

how do you fix the error with saving? - Beta tester script

I am trying to make a script where it saves a value if you played during beta, but I gives me the error 19:49:51.758 - 104: Cannot store Instance in data store. Data stores can only accept valid UTF-8 characters. Code:

local betastatus = game:GetService('DataStoreService'):GetDataStore('Tester')
local status = game:GetService('ServerStorage'):WaitForChild('BetaStatus')
game.Players.PlayerAdded:Connect(function(player)
	local scope = 'userid-' .. player.userId
	status.Value = betastatus:GetAsync(scope)
	print('Set')
	status.Changed:Connect(function()
	local scope = 'userid-' .. player.userId
	betastatus:SetAsync(status.Value, scope)
	print('Saved')
end)
end)
game.Players.PlayerAdded:Connect(function(player)
	if status.Value == 1 then
	status.Value = 2
	print('Now a beta tester!')
	betastatus:SetAsync(status.Value, player)
	print('Saved!')
	elseif status.Value == 2 then
	print('Already a beta tester!')
	end

end)

I am just wondering where the error is and how to fix it :D *1 = false *2 = true

1 answer

✓ Accepted answer

For first, use scope, status.Value not status.Value, scope

And you dont need to use two PlayerAdded function

Here is the fixed script:

local betastatus = game:GetService('DataStoreService'):GetDataStore('Tester')
local status = game:GetService('ServerStorage'):WaitForChild('BetaStatus')

game.Players.PlayerAdded:Connect(function(player)
	local scope = 'userid-' .. player.userId
	status.Value = betastatus:GetAsync(scope)
	print('Set')
	status.Changed:Connect(function()
		local scope = 'userid-' .. player.userId
		betastatus:SetAsync(scope,status.Value) -- Simple change the status.Value, scope to scope,status.Value
		wait()
		print('Saved')
	end)

	if status.Value == 1 then
		status.Value = 2
		print('Now a beta tester!')
		betastatus:SetAsync(scope,status.Value) -- Here i changed. you need to put 'userid-' .. player.userId in key, in another script you dont put it.
		print('Saved!')
	elseif status.Value == 2 then
		print('Already a beta tester!')
	end
end)

Hope it helped :)

Errors? tell-me on comments.

1 comment

0

Thx :)

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