Im making a obby with saving stages. It some what works but it sometimes saves. I can up with a solution of when you step on the check point it autosaves to the players datastore. I thought this would be a good idea till I got this error: attempt to index function with ‘SetAsync’
I cant find anyway to fix it please help.
How Im Saving:
local DataStoreService = game:GetService("DataStoreService")
local saveStage = DataStoreService:GetDataStore("Stages")
function saveStage(player)
local success, errormessage = pcall(function()
saveStage:SetAsync(player.UserId.."-stages", player.StageOn.Value)
end)
if success then
print("Player Stage Was Saved!")
else
print("There Was A Problem Getting Player Stage!")
warn(errormessage)
end
end
This function calls when the part is touched and is 1 stage higher then before
You are setting the value but you never extract it from the data store. You have to use the GetAsync() function to get the data and then set the StageOn value to the datastore value.
You’re literally attempting to define both a variable, and a function together
Rename your function or your GetDataStore name
local DataStoreService = game:GetService("DataStoreService")
local saveStage = DataStoreService:GetDataStore("Stages")
function save(player)
local success, errormessage = pcall(function()
saveStage:SetAsync(player.UserId.."-stages", player.StageOn.Value)
end)
if success then
print("Player Stage Was Saved!")
else
print("There Was A Problem Getting Player Stage!")
warn(errormessage)
end
end