We’re making a system using Coins… the aim is to touch a model and then get coins from it, but there is hundreds of them.
Now, each one relies on touching it for it to give the player a coin, none of them work obviously because the datastore is full up with hundreds of those requests.
Updating the datastore each time you do anything in a game (picking up coins in ur example) is a very bad idea, either save it somewhere temporarily in your game, and save it when the player leaves, or save every players data in the game every x minutes
Where should I change it instead? I am the scripter for this, btw. Here it the script for the coin:
local DataStoreService = game:GetService("DataStoreService")
local CoinsDataStore = DataStoreService:GetDataStore("CoinsDataStore")
local RespawnTime = 180
function savePlayerData(player)
local leaderstats = player:FindFirstChild("leaderstats")
if leaderstats then
local coins = leaderstats:FindFirstChild("Hay")
if coins then
CoinsDataStore:SetAsync(player.UserId .. "Hay", coins.Value)
end
end
end
function loadPlayerData(player)
local success, result = pcall(function()
return CoinsDataStore:GetAsync(player.UserId .. "Hay")
end)
if success and result ~= nil then
local leaderstats = player:FindFirstChild("leaderstats")
if leaderstats then
local coins = leaderstats:FindFirstChild("Coins")
if coins then
coins.Value = result
end
end
end
end
function onTouch(otherPart)
local player = game.Players:GetPlayerFromCharacter(otherPart.Parent)
if player then
local leaderstats = player:FindFirstChild("leaderstats")
if not leaderstats then
return
end
local coins = leaderstats:FindFirstChild("Hay")
if coins then
coins.Value = coins.Value + 1
end
script.Parent.CanTouch = false
script.Parent.Transparency = 1
script.Parent.Parent.Hay.Attachment.Rays.Enabled = false
script.Parent.Parent.Hay.Attachment.Glow.Enabled = false
script.Parent.Parent.Hay.PointLight.Enabled = false
wait(RespawnTime)
script.Parent.CanTouch = true
script.Parent.Transparency = 0
script.Parent.Parent.Hay.Attachment.Rays.Enabled = true
script.Parent.Parent.Hay.Attachment.Glow.Enabled = true
script.Parent.Parent.Hay.PointLight.Enabled = false
end
end
function onPlayerRemoving(player)
savePlayerData(player)
end
function onPlayerAdded(player)
loadPlayerData(player)
end
script.Parent.Touched:Connect(onTouch)
game.Players.PlayerRemoving:Connect(onPlayerRemoving)
game.Players.PlayerAdded:Connect(onPlayerAdded)