I am making a sword fighting game and I can't figure out how to fix it
here's 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
local playerData = Instance.new("Folder")
playerData.Name = player.Name
playerData.Parent = game.ServerStorage.PlayerData
local playerData = Instance.new("StringValue")
equipped.Name = "Equipped"
equipped.Parent = playerData
local inventory = Instance.new("Folder")
inventory.Name = "Inventory"
inventory.Parent = playerData
player.CharacterAdded:Connect(function(character)
character.Humanoid.WalkSpeed = 16
character.Humanoid.Died:Connect(function()
-- Whenever somebody dies, this event will run
if character.Humanoid and character.Humanoid:FindFirstChild("creator") then
game.ReplicatedStorage.Status.Value = tostring(character.Humanoid.creator.Value).." KILLED "..player.Name
end
if character:FindFirstChild("GameTag")then
character.GameTag:Destroy()
end
player:LoadCharacter()
end)
end)
-- Data Stores
local player_data
local weaponsData
local equippedData
if player_data ~= nil then pcall(function()
player_data = dataStores:GetAsync(player.UserId.."-Bucks") --1736284-Bucks
end)
if player_data ~= nil then pcall(function()
weapons_data = dataStores:GetAsync(player.UserId.."-Weps") --1736284-Bucks
end)
if player_data ~= nil then pcall(function()
eqipped_data = dataStores:GetAsync(player.UserId.."-EquippedValue") --1736284-Bucks
end)
-- Player has saved data , load it in
bucks.Value = player_data
else
-- New player
bucks.Value = defaultCash
end
if weaponsData then
-- For loop through the weapons saved
-- Load them in
-- Set the equipped vvalue
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) <--------- where the error is

2 comments
This is from alvin_Blox's how to make a roblox game series
It depends on what you want to fix. If it is the entire game you would need multiple scripts for the game.