#Don't work collectable if press button E :(
1 messages · Page 1 of 1 (latest)
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)
why the actual fuck are u doing the data storage inside of the proximity prompt?
Bro, I don’t understand much about this, that’s why I’m asking for help.
What is not working? 🙂
When you hold down the letter E, the piece of paper is not counted in the leaderstats and does not disappear
** You are now Level 1! **
Nope, I found it on the Internet and tried to adapt it. Although where the guide got it from, I can only guess...
From what i can see, the script would automaticly stop here, since you are trying to get a player from a character that you don't give.
The triggered event gives a player in the callback, so you can define player in the function, like this:
Sheet.ProximityPrompt.Triggered:Connect(function(player)
-- now do what you need too
end)
I tried it but it didn't work
** You are now Level 3! **
You need to delete the line where it says local player = ...