Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do i fix the door script in my game? (Script Question)

Asked by 5 years ago

In my new game i made a script for the doors to new areas, but the script i made doesn't work the way i wanted it will make you buy it again once you re-log! Here is my script can you tell me how to fix it and make it save?

local DSS = game:GetService("DataStoreService")
    local Storage = DSS:GetDataStore("Score")

    local Door = script.Parent
    local debounce = true

    game:GetService("Players").PlayerAdded:Connect(function(player)
        local bool = Instance.new("BoolValue")
        bool.Name = "RemoveINH"
        bool.Value = false
        bool.Parent = player

        local success, result = pcall(function()
            Storage:GetAsync(player.UserId)
        end)

        if not success then
            warn(result)
        else
            local LoadValue = Storage:GetAsync(player.UserId)
            if LoadValue then
                bool.Value = LoadValue
                print(bool.Value)
            end
        end
    end)

    game:GetService("Players").PlayerRemoving:Connect(function(player)
        Storage:SetAsync(player.UserId, player:WaitForChild("RemoveINH").Value)
    end)

    Door.Touched:Connect(function(hit)
        if debounce == false then return end
        debounce = false
        print("Door Hit")
        local human = hit.Parent:FindFirstChild("Humanoid")
        if human ~= nil then
            print("Human touched door")
            local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
            if player ~= nil then
                local sp = player:WaitForChild("leaderstats"):WaitForChild("Money")
                local check = player:WaitForChild("RemoveINH")
                if check.Value == false and sp.Value >= 1500 then
                    print("Human passed test")
                    check.Value = true
                    sp.Value = sp.Value - 1500
                    Door.CanCollide = false
                    wait(0.129)
                    Door.CanCollide = true
                elseif check.Value == true then
                    print("Human already has access")
                    Door.CanCollide = false
                    wait(0.129)
                    Door.CanCollide = true
                end
            end
        end
        debounce = true
    end)

1 answer

Log in to vote
0
Answered by 5 years ago

I would consider using DataStore2 - the open source module featured in an article on the Developer's forum. Here's the link, which also provides a good youtube tutorial.

https://devforum.roblox.com/t/how-to-use-datastore2-data-store-caching-and-data-loss-prevention/136317

Ad

Answer this question