Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

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

Asked by 3 years ago

Please provide more explanation in your question. If you explain exactly what you are trying to accomplish, it will be much easier to answer your question correctly.
local DSS = game:GetService("DataStoreService")
local cars_store = DSS:GetDataStore("player_cars")
local SS = game:GetService("ServerStorage")
local dealer = game.Workspace.dealer

function spawn_car(player)
    local player_id = player.UserId -- idk what to add next
    print(player_id)

    cars_store:SetAsync(player_id, cars_store)
end

dealer.head.ProximityPrompt.Triggered:Connect(spawn_car)
0
what line is the error at? JesseSong 3916 — 3y
0
10 jeremqpmfpi 41 — 3y
0
Datastores can only hold strings, booleans etc.. JesseSong 3916 — 3y
0
Just by looking at it, it seems the argument of :SetAsync is missing JesseSong 3916 — 3y
View all comments (5 more)
0
SetAsync requires another argument which is the value. cars_store is the variable JesseSong 3916 — 3y
0
did you try my answer?  JesseSong 3916 — 3y
0
also what do you want the script to do? JesseSong 3916 — 3y
0
since you aren't being that descriptive in your question, i don't know what you want to accomplish, so i can't really help you properly. JesseSong 3916 — 3y
0
make sure your question is well - descriptive. see this to learn how to post good questions/answers: https://scriptinghelpers.org/help/how-post-good-questions-answers JesseSong 3916 — 3y

1 answer

Log in to vote
0
Answered by
JesseSong 3916 Moderation Voter Community Moderator
3 years ago
Edited 3 years ago

I haven't tested this out. But by looking at it it seems that in line 10, you're missing a value. The script is expecting an argument, but it got an instance which is cars_store in this case.

Simply replace this:

cars_store:SetAsync(player_id, cars_store)

With this:

cars_store:SetAsync(player_id, 50) --change 50 to ur value name

(EDIT:)

Also, don't forget to reference the player!

Full script:

local player = game.Players.PlayerAdded:Connect(function(player)
local DSS = game:GetService("DataStoreService")
local cars_store = DSS:GetDataStore("player_cars")
local SS = game:GetService("ServerStorage")
local dealer = game.Workspace.dealer

function spawn_car(player)
    local player_id = player.UserId -- idk what to add next
    print(player_id)

    cars_store:SetAsync(player_id, 50)
end
end)
dealer.head.ProximityPrompt.Triggered:Connect(spawn_car)

If you need any more assistance, ask and I'll try to help you.

JesseSong!

0
also, do let me know if you have more issues. JesseSong 3916 — 3y
Ad

Answer this question