Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Datasave Code not working with complete server?

Asked by 6 years ago

The code is below.

It saves your coins you collect but the game fails to show everyone the coins you lose when you purchase something in the coin shop.

Here is the Data Save Script:

function onPlayerEntered(player)
wait()
player:WaitForDataReady()
repeat wait() until player:FindFirstChild("leaderstats")
if player.DataReady then
if player:findFirstChild("leaderstats") then
local score = player.leaderstats:GetChildren()
for i = 1,#score do
local ScoreLoaded = player:LoadNumber(score[i].Name)
wait()
if ScoreLoaded ~= 0 then
score[i].Value = ScoreLoaded
end
end
end
end
end

function onPlayerLeaving(player)
if player:findFirstChild("leaderstats") then
local score = player.leaderstats:GetChildren()
for i = 1,#score do
player:SaveNumber(score[i].Name,score[i].Value)
end
end
end

game.Players.PlayerAdded:connect(onPlayerEntered)
game.Players.PlayerRemoving:connect(onPlayerLeaving)

Here is the code to purchase something in the shop:

local player=game.Players.LocalPlayer
local leaderboard=player:WaitForChild("leaderstats")
local button=script.Parent
local price=button:WaitForChild("Price")
local item=button:WaitForChild("ItemName")
local rs=game:GetService("ReplicatedStorage")

button.MouseButton1Click:connect(function()
 if leaderboard.Coins.Value>=price.Value then
  leaderboard.Coins.Value=leaderboard.Coins.Value-price.Value
  local item=rs:WaitForChild(item.Value)
  item:Clone().Parent=player.StarterGear
     item:Clone().Parent=player.Backpack

 end
end)

while wait()do
 button.Text=item.Value.."-"..price.Value
end

1 answer

Log in to vote
0
Answered by 6 years ago

Line 20 on the first script you misspelled FindFirstChild and switch to Connect, connect is deprecated.

Ad

Answer this question