local db = true
script.Parent.Touched:connect(function(hit)
if hit.Parent:FindFirstChild(“Humanoid”) ~= nil then
if db == true then
db = false
script.Parent.Transparency = 1
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + 500
script.Sound:Play()
script.Parent.Transparency = 1
wait(1)
db = true
script.Parent.Transparency = 0
end
end
end)
Also you can’t copy and paste " ", quoted things. You need to requote the words “DataStoreService” and “User_” (Why there is a red line under those words)
Btw it will be more complicated than just this if you want to save other stuff along with coins, and to make sure data loads, and to back up data etc. I’d recommend using datastore2 and learning how it works
local ToolFolder = game:GetService(“ServerStorage”):FindFirstChild(“SavedTools”)
local DataStoreService = game:GetService(“DataStoreService”)
local SaveData = DataStoreService:GetDataStore(“SaveData”)
game.Players.PlayerAdded:Connect(function(Player)
local ToolData = SaveData:GetAsync(Player.UserId)
local Backpack = Player:WaitForChild("Backpack")
local StarterGear = Player:WaitForChild("StarterGear")
if ToolData ~= nil then
for i, v in pairs(ToolData) do
if ToolFolder:FindFirstChild(v) and Backpack:FindFirstChild(v) == nil and StarterGear:FindFirstChild(v) == nil then
ToolFolder[v]:Clone().Parent = Backpack
ToolFolder[v]:Clone().Parent = StarterGear
end
end
end
Player.CharacterRemoving:Connect(function(Character)
Character:WaitForChild("Humanoid"):UnequipTools()
end)
end)
game.Players.PlayerRemoving:Connect(function(Player)
local ToolTable = {}
for i, v in pairs(Player.Backpack:GetChildren()) do
table.insert(ToolTable, v.Name)
end
if ToolTable ~= nil then
SaveData:SetAsync(Player.UserId, ToolTable)
end
local ToolFolder = game:GetService(“ServerStorage”):FindFirstChild(“SavedTools”)
local DataStoreService = game:GetService(“DataStoreService”)
local SaveData = DataStoreService:GetDataStore(“SaveData”)
game.Players.PlayerAdded:Connect(function(Player)
local ToolData = SaveData:GetAsync(Player.UserId)
local Backpack = Player:WaitForChild("Backpack")
local StarterGear = Player:WaitForChild("StarterGear")
if ToolData ~= nil then
for i, v in pairs(ToolData) do
if ToolFolder:FindFirstChild(v) and Backpack:FindFirstChild(v) == nil and StarterGear:FindFirstChild(v) == nil then
ToolFolder[v]:Clone().Parent = Backpack
ToolFolder[v]:Clone().Parent = StarterGear
end
end
end
Player.CharacterRemoving:Connect(function(Character)
Character:WaitForChild("Humanoid"):UnequipTools()
end)
end)
game.Players.PlayerRemoving:Connect(function(Player)
local ToolTable = {}
for i, v in pairs(Player.Backpack:GetChildren()) do
table.insert(ToolTable, v.Name)
end
if ToolTable ~= nil then
SaveData:SetAsync(Player.UserId, ToolTable)
end
end)
Yea this isn’t gonna work if the player dies or anything like that in between joining and leaving… it would just revert data (ik it’s not your code btw)