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
The problem is that you are only setting the key, so instead of true, its just the key and the key is lets just say is: 858581143true. And we know that is not a boolean value. You also are setting and getting a different key. You also don't need the .Value
when you were setting it because its a variable and not a boolvalue in the explorer. I would do this:
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",dooropened) 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 data = door:GetAsync(player.UserId.."Dooropened") if sucess then dooropened.Value = data end end) end)
Hope this helps!