Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Im trying to make a boolean datastore for a simulator game, i cant seem to get this to work!?

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

0

i think its becuase you aren't setting the async

0

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

0

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.

1 answer

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!

This discussion is preserved as it was. New answers, comments, and votes are closed.