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

Save script not working. Anybody got an explanation?

Asked by 5 years ago

So, I was following a tutorial for a sword fighting game, and I got to a point for saving data. I have looked over the video, and have published the game, but the save data is not working. Here was the code.

local dataStores = game:GetService("DataStoreService"):GetDataStore("BucksDataStore")

local defaultCash = 50

local playersLeft = 0

game.Players.PlayerAdded:Connect(function(player)

playersLeft = playersLeft + 1

local leaderstats = Instance.new("Folder")

leaderstats.Name = "leaderstats"

leaderstats.Parent = player

local bucks = Instance.new("IntValue")

bucks.Name = "Bucks"

bucks.Value = 0

bucks.Parent = leaderstats

player.CharacterAdded:Connect(function(character)

character.Humanoid.WalkSpeed = 16

character.Humanoid.Died:Connect(function()

-- When someone dies, this will happen

if character:FindFirstChild("GameTag") then

character.GameTag:Destroy()

end

player:LoadCharacter()

end)

end)

-- Data Stores

local player_data

pcall(function()

player_data = dataStores:GetASync(player.UserId.."-Bucks")

end)

if player_data ~= nil then

-- Player has saved data, load it in

bucks.Value = player_data

else

-- New Player

bucks.Value = defaultCash

end

end)



local bindableEvent = Instance.new("BindableEvent")



game.Players.PlayerRemoving:Connect(function(player)

pcall(function()

dataStores:SetASync(player.UserId.."-Bucks",player.leaderstats.Bucks.Value)

print("Saved")

playersLeft = playersLeft - 1

bindableEvent:Fire()

end)

end)



game:BindToClose(function()

-- This will be triggered upon shutdown

while playersLeft > 0 do

bindableEvent.Event:Wait()

end

end)

And the error that I was given in the output was:

InsertService cannot be used to load assets from the client

Can anybody explain to me what happened, and why the saving is not working?

0
That error is probably from a plugin, not your script InfiniteWhileLoop 19 — 5y
0
its definitely not from this script, as this is most likely a server script theking48989987 2147 — 5y

Answer this question