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

Why Won't My Remote Event Called DataStore Function?

local event = Instance.new("RemoteEvent") -- creates the event object
event.Parent = game.Workspace -- puts the event into the Workspace
event.Name = "MyServerEvent"
local RepStorage = game:GetService("ReplicatedStorage")
local remote = RepStorage:WaitForChild("Remote")
local Button = script.Parent
local DSService = game:GetService('DataStoreService'):GetDataStore('ToonApperance')
	--SaveThemUp

event.OnServerEvent:connect(function(player)
--
local Tlayer = player.Character
local ToonChoosen = Tlayer:WaitForChild("Chest").ValuesFolder.ToonChoosen	
local ToonColorHead = Tlayer:WaitForChild("ToonHead").ValuesFolder.Head
local ToonShirtColor = Tlayer:WaitForChild("Chest").ValuesFolder.Shirt	
local ToonArmColor = Tlayer:WaitForChild("Chest").ValuesFolder.Arms
local ToonLegColor = Tlayer:WaitForChild("Chest").ValuesFolder.Legs	
local ToonBttomsColor = Tlayer:WaitForChild("Chest").ValuesFolder.Bottoms	
--
print("Save Event Recieved Saving")
local UniqueKey = 'id-'..player.userId
local Savetable = {ToonChoosen.Value,ToonColorHead.Value,ToonShirtColor.Value,ToonBttomsColor.Value,ToonLegColor.Value,ToonArmColor.Value}
DSService:SetAsync(UniqueKey,Savetable)
end)


My datastore script will not work for some unknown reason for example. I press the gui button and the remote event works because print("Save Event Recieved Saving") shows up in the dev console but the values do not save at all. As when i try to call it using getasync the value is not returned to any of the values i wanted to save. I tried looking at many datastore examples most are just leaderboard stuff. Help please!

Below is the get async

local DataStore = game:GetService("DataStoreService"):GetDataStore("ToonApperance")
game.Players.PlayerAdded:connect(function(plr)
--Now For Defining Variables(Creates Values Too)
local UniqueKey = 'id-'..plr.userId
local ToonChoosen = Instance.new("IntValue", plr)
local ToonColorHead = Instance.new("BrickColorValue", plr)
local ToonShirtColor = Instance.new("BrickColorValue", plr)
local ToonArmColor = Instance.new("BrickColorValue", plr)
local ToonLegColor = Instance.new("BrickColorValue", plr)
local ToonBttomsColor = Instance.new("BrickColorValue", plr)
ToonChoosen.Name = "ToonChoosen"
ToonColorHead.Name = "ToonColorHead"
ToonShirtColor.Name = "ToonShirtColor"
ToonArmColor.Name = "ToonArmColor"
ToonLegColor.Name = "ToonLegColor"
ToonBttomsColor.Name = "ToonBttomsColor"
local GetSaved = DataStore:GetAsync(UniqueKey)
if GetSaved then 
ToonChoosen.Value = GetSaved[1]
ToonColorHead.Value = GetSaved[2]
ToonShirtColor.Value = GetSaved[3]
ToonArmColor.Value = GetSaved[4]
ToonLegColor.Value = GetSaved[5]
ToonBttomsColor.Value = GetSaved[6]
print("Value Set For Toon")
end
end)

11 comments

0

When you use GetAsync to retrieve what you saved, what does it return? nil? Also, you have an issue on line 28 where you're saving VariablesToSave5 twice -- I imagine the second time it should be VariablesToSave6.

0

It doesnt return a nil value. this is the getasync script

0

What does it return then? Regardless of what your GetAsync script does that you just added to the OP, what it gives you depends on what was stored in the DataStore to begin with.

0

13:28:43.274 - Cannot store Array in DataStore

0

also rewrote the script

0

That's an error you'll get from saving. After rewriting the script, do you still get that error?

0

yeah thats the error i get now its something to do with the table on line 22

0

Here is a printTable function: http://pastebin.com/E7JXRffp Use this to print out Savetable before doing SetAsync on line 23 and post back with the results.

0

where does this go? Line 22? and do i have to remove the things already in line 22?

0

No, leave your SetAsync code the same. Paste that printTable function at the top of the script, and then between lines 22 and 23 put printTable(Savetable)

0

{ [1] = 1; [2] = Pink; [3] = Br. yellowish orange; [4] = Pink; [5] = Pink; [6] = Mulberry; } thats what it printed

1 answer

✓ Accepted answer

The error you're getting "Cannot store Array in DataStore" is misleading. The issue is that you're trying to save BrickColors to the DataStore -- DataStores cannot store ROBLOX types. You'll need to save the name or number of the BrickColor instead. Try

Line 22 of SetAsync block:

local Savetable = {ToonChoosen.Value, ToonColorHead.Value.Name,ToonShirtColor.Value.Name, ToonBttomsColor.Value.Name, ToonLegColor.Value.Name, ToonArmColor.Value.Name}

Lines 19-24 of GetAsync block:

ToonChoosen.Value = GetSaved[1]
ToonColorHead.Value = BrickColor.new(GetSaved[2])
ToonShirtColor.Value = BrickColor.new(GetSaved[3])
ToonArmColor.Value = BrickColor.new(GetSaved[4])
ToonLegColor.Value = BrickColor.new(GetSaved[5])
ToonBttomsColor.Value = BrickColor.new(GetSaved[6])

1 comment

0

You are truly a life saver could i add you on roblox!

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