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)
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)
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.