for some reason, when I tested my game in public with 2 accounts, on each screen it says the other player has 0 but it says that the current account has an amount (like 50 or whatever they were given). Here is my datastore script which is not working.
--serverScriptService server side script
local DSS = game:GetService("DataStoreService")
local mainDS = DSS:GetDataStore("CoinsData")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local events = ReplicatedStorage:FindFirstChild("Events")
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder", player)
leaderstats.Name = "leaderstats"
local coins = Instance.new("IntValue", leaderstats)
coins.Name = "Coins"
local data = mainDS:GetAsync(player.UserId)
if data then
if data[1] then
coins.Value = data[1]
end
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local leaderstats = player:WaitForChild("leaderstats")
local coins = leaderstats:WaitForChild("Coins")
mainDS:SetAsync(player.UserId, {coins.Value})
end)
here is the scripts that gives money
--StarterCharacterScript, local script
local chest = game.Workspace.Chest
local Open = chest.ChestOpen:GetChildren()
local Closed = chest.ChestClosed:GetChildren()
local prompt = game.Workspace.Chest.Button.ProximityPrompt
local function ClosedChestTrans(Transparency)
for i,v in pairs(Closed) do
v.Transparency = Transparency
end
end
local function OpenChestTrans(Transparency)
for i,v in pairs(Open) do
v.Transparency = Transparency
end
end
ClosedChestTrans(0)
OpenChestTrans(1)
prompt.Triggered:Connect(function(plr)
if plr == game.Players.LocalPlayer then
ClosedChestTrans(1)
OpenChestTrans(0)
game.Workspace.Chest.Button.ProximityPrompt.Enabled = false
game.Players.LocalPlayer.leaderstats.Coins.Value += 500
game.Players.LocalPlayer.PlayerGui.Chest.Enabled = true
end
end)
second coin giving script
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local toolName = "Wood"
game.Workspace.Guide:WaitForChild("Head")
game.Workspace.Guide.Head:WaitForChild("ProximityPrompt")
local tool
local deb = 0
while wait(0) do
-- Check if the tool is equipped by the player
tool = character:FindFirstChild(toolName)
-- Enable proximity prompt if the tool exists and is equipped
if tool then
deb = 0
game.workspace.Guide.Head.ProximityPrompt.Enabled = true
-- Move the tool to game.ReplicatedStorage.Supplies when the prompt is triggered
game.workspace.Guide.Head.ProximityPrompt.Triggered:Connect(function(plr)
if deb == 0 and plr == player then
tool.Parent = game.ReplicatedStorage.Supplies
player.leaderstats.Coins.Value += 50
deb = 1
end
end)
else
game.workspace.Guide.Head.ProximityPrompt.Enabled = false
end
end
ALL HELP APPRECIATED THANKS!