What im trying to do
I am trying to make a door that costs a value from leaderstats, lets say 50, and take away that value from the total value and then open the door, i got that part down but i need it to save so that if the player joins back they can acess that door again without having to pay again.
My script
local dsService = game:GetService("DataStoreService")
local door = dsService:GetDataStore("DoorBuyDS")
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
hit.Parent:GetPlayerFromCharacter()
print("humanoid found so its a player")
local Cost = 50
local dooropened = false
local Level = player.leaderstats.Cash.Value
if Level >= Cost then
Level = Level - Cost
dooropened = true
door:SetAsync(player.UserId..dooropened.Value)
print(door)
script.Parent.CanCollide = false
script.Parent.Transparency = 1
wait()
else
local dooropened = false
end
end
end)
game.Players.PlayerAdded:Connect(function(player)
local sucess, errormessage = pcall(function()
local data
if sucess then
dooropened.Value = data
end
data = door:GetAsyc(player.UserId.."Dooropened")
end)
end)
What i've tried
I have tried asking on diffrent discord servers to help but nobody seems online and i also tried looking for help on youtube. Thanks

3 comments
i think its becuase you aren't setting the async
Problem on lines 11 and 12, You are setting the Level variable to the current cash value. Remove the .Value on line 11, and add it to the check on line 12
Thats not a problem, you can see my answer and maybe its wrong and you can teach me something, or its right and I can teach you something.