Door Data Won't Save to Data Store

Hello.

I am trying to save someone buying a door with my in-game currency (coins) to a data store, meaning that I would like the data stores to remember who bought the door and that they own that door.

My code currently is not working, and I have tried for hours to fix it to no avail. Any help is appreciated!

local data = game:GetService("DataStoreService")
local store = data:GetDataStore("iicon123")
local cd = 0
local aa = nil

script.Parent.Touched:connect(function(part)
    if part.Parent:FindFirstChild("Humanoid") then
		aa = game.Players[part.Parent.Name]
        if game.Players:FindFirstChild(part.Parent.Name).leaderstats["Coins"].Value >= houseprice then
            if not game.Workspace:FindFirstChild(part.Parent.Name.."'s House") then 
                if script.Parent.Parent.Parent.Owner.Value == "" then 
                    game.Players:FindFirstChild(part.Parent.Name).leaderstats["Coins"].Value = game.Players:FindFirstChild(part.Parent.Name).leaderstats["Coins"].Value - houseprice
                    script.Parent.Parent.Parent.Owner.Value = part.Parent.Name 
					script.Parent.Parent.Name = part.Parent.Name.."'s House"
					
				end
				if cd == 0 then
					if store:GetAsync(aa.UserId.."House1") == "yes" then
						wait()
						print('aa = yes')		
						cd = 1
						wait(1)
						cd = 0
					end	
				end
			end
        end
    end
end)

Is there anywhere in this script, or in another script where you add the data to the data store with: :SetAsync()

Right here is where I do :GetAsync

Not :GetAsync

It’s :SetAsync

:GetAsync Will get the data, :SetAsync will set the data

Ah, I misread :SetAsync() as :GetAsync() on your post. Thanks for the help

No problem, just message me if you need more help with setting the data!

Yeah, I added a set async in, yet it still fails to save the data.

My current code:

local data = game:GetService("DataStoreService")
local store = data:GetDataStore("iicon123")
local cd = 0
local aa = nil

script.Parent.Touched:connect(function(part)
    if part.Parent:FindFirstChild("Humanoid") then
		aa = game.Players[part.Parent.Name]
        if game.Players:FindFirstChild(part.Parent.Name).leaderstats["Coins"].Value >= houseprice then
            if not game.Workspace:FindFirstChild(part.Parent.Name.."'s House") then 
                if script.Parent.Parent.Parent.Owner.Value == "" then 
                    game.Players:FindFirstChild(part.Parent.Name).leaderstats["Coins"].Value = game.Players:FindFirstChild(part.Parent.Name).leaderstats["Coins"].Value - houseprice
                    script.Parent.Parent.Parent.Owner.Value = part.Parent.Name 
					script.Parent.Parent.Name = part.Parent.Name.."'s House"
					store:SetAsync(aa.UserId..".house1",script.Parent.Parent.Parent.Owner.Value)
					
				end
				if cd == 0 then
					if store:GetAsync(aa.UserId.."House1") == "yes" then
						wait()
						print('aa = yes')		
						cd = 1
						wait(1)
						cd = 0
					end	
				end
			end
        end
    end
end)

For your code, it appears you are setting the owner value instead of yes or no, also instead of “yes” I would use bools (true/false).

I changed the “‘yes’” to a “true”, but it doesn’t work still.

On this line, you are setting the value to something else. Change it to store:SetAsync(aa.UserId..".house1", true To test it

It unfortunately did not work.

It should work, as I am away from my computer (using phone) I can’t test it. Try to make sure the code where it sets the data is getting called

It is currently turning up this error:
RobloxScreenShot20220404_225532738 (2)

This line, your key is incorrect, that may be what is going on. So change the key to the one you put on SetAsync

It is now printing the “aa = yes”, however it does not save the data. Is it alright with you if I contact you tomorrow around 5pm EST, as it is rather late for me.

Yes, by then I should be home and will have access to my pc to help

Alright, will be talking to you then.

Do you have access to API services turned on in the game settings?

Yes I do have API services enabled.

1 Like

Hello again, my good associate.