#Don't work collectable if press button E :(

1 messages · Page 1 of 1 (latest)

misty nimbus
#

I wanted to make sure that when you press the E button, the sheet is collected and counted in the leaderstats, but I don’t really understand ProximityPrompt, that’s why I’m asking for help

#
local DataStoreService = game:GetService("DataStoreService")
local SheetsDataStore = DataStoreService:GetDataStore("SheetsDataStore")

local Sheet = script.Parent.Parent.Sheet

function savePlayerData(player)
    local leaderstats = player:FindFirstChild("leaderstats")
    if leaderstats then
        local Sheets = leaderstats:FindFirstChild("Sheets")
        if Sheets then
            SheetsDataStore:SetAsync(player.UserId .. "_Sheets", Sheets.Value)
        end
    end
end

function loadPlayerData(player)
    local success, result = pcall(function()
        return SheetsDataStore:GetAsync(player.UserId .. "_Sheets")
    end)
    if success and result ~= nil then
        local leaderstats = player:FindFirstChild("leaderstats")
        if leaderstats then
            local Sheets = leaderstats:FindFirstChild("Sheets")
            if Sheets then
                Sheets.Value = result
            end
        end
    end
end

Sheet.ProximityPrompt.Triggered:Connect(function() 
    local player = game.Players:GetPlayerFromCharacter()
    if player then
        local leaderstats = player:FindFirstChild("leaderstats")
        if not leaderstats then

            return
        end
        local Sheets = leaderstats:FindFirstChild("Sheets")
        if Sheets then
            Sheets.Value = Sheets.Value + 1 -- Change the +1 to how much currency you want that sheet to give
        end
        script.Parent.CanTouch = false 
        script.Parent.Transparency = 1

    end
end)

function onPlayerRemoving(player)
    savePlayerData(player)
end

function onPlayerAdded(player)
    loadPlayerData(player)
end

script.Parent.ProximityPrompt.Triggered:Connect(Sheet)
game.Players.PlayerRemoving:Connect(onPlayerRemoving)
game.Players.PlayerAdded:Connect(onPlayerAdded)
manic musk
#

why the actual fuck are u doing the data storage inside of the proximity prompt?

misty nimbus
#

Bro, I don’t understand much about this, that’s why I’m asking for help.

misty nimbus
#

When you hold down the letter E, the piece of paper is not counted in the leaderstats and does not disappear

short groveBOT
#

studio** You are now Level 1! **studio

misty nimbus
#

Nope, I found it on the Internet and tried to adapt it. Although where the guide got it from, I can only guess...

tiny hull
misty nimbus
#

I tried it but it didn't work

short groveBOT
#

studio** You are now Level 3! **studio

tiny hull
misty nimbus
#

оуу

#

YEAH, it working

#

Thank you very much<3