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

How do I fix my door script? I have spent so much time on this please help!

Asked by 4 years ago
Edited 4 years ago

Please help me out here I have no idea why my door script is not working, I have spent an hour experimenting and it still wont work! It will take your currency away again if you relog! Here is my door script:

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 = "RemoveMI1"
        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("RemoveMI1").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("@$")
                local check = player:WaitForChild("RemoveMI1")
                if check.Value == false and sp.Value >= 300 then
                    print("Human passed test")
                    check.Value = true
                    sp.Value = sp.Value - 300
                    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)

Please help me out!!!

1 answer

Log in to vote
1
Answered by
Leamir 3138 Moderation Voter Community Moderator
4 years ago
Edited 4 years ago

Hello, dottsa_legend!

The only problem is that the time is too low

Please try corretly iddenting your code

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 = "RemoveMI1"
        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("RemoveMI1").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("@$")
                local check = player:WaitForChild("RemoveMI1")
                if check.Value == false and sp.Value >= 300 then
                    print("Human passed test")
                    check.Value = true
                    sp.Value = sp.Value - 300
                    Door.CanCollide = false
                    wait(1) -- Time was too low, recommend changing to 1 or 1.5
                    Door.CanCollide = true
                elseif check.Value == true then
                    print("Human already has access")
                    Door.CanCollide = false
                    wait(1) - Time was too low, recommend changing to 1 or 1.5
                    Door.CanCollide = true
                end
            end
        end
        debounce = true
    end)

Remember that wait() uses seconds

If you need any more help, post a comment here, or message me on roblox

0
I expanded on my description of the question! It will take away At Dollars from the player again if they re-log! dottsa_legend 16 — 4y
1
@dottsa_legend why don't you just save their current score when they leave? and then load when they join? Leamir 3138 — 4y
0
I don't know how to dottsa_legend 16 — 4y
1
Just pass as the SetAsync's Argument the current player Score, like: `DataStore:SetAsync(player.UserId, score)` Leamir 3138 — 4y
Ad

Answer this question