Hello again. I have been having errors in my code again if someone can provide help, that would be great.
The problem I am having is in
local dataStores = game:GetService("DataStoreService"):GetDataStore("MoneyDataStore")
local defaultCash = 100
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local money = Instance.new("IntValue")
money.Name = "Money"
money.Value = 0
money.Parent = leaderstats
player.CharacterAdded:Connect(function(charter)
charter.Humanoid.WalkSpeed = 16
charter.Humanoid.Died:Connect(function()
-- Whenever someone dies, this event will run/play
if charter.Humanoid and charter.Humanoid:FindFirstChild("creator")then
game.ReplicatedStorage.Status.Value = tostring(charter.Humanoid.creator.Value).. " Killed " ..player.Name
end
if charter:FindFirstChild("GameTag") then
charter.GameTag:Destroy()
end
player:LoadCharter()
end)
end)
end)
--Data Stores
local player_data
pcall(function()
player_data = dataStores:GetAsync(player.UserId.."-Money") --UserID, This saves the data that they may have had
end)
if player_data ~= nil then
--player has saved data,load it in
Money.Value = player_data
end
else
--new player
bucks.Value = defaultCash
end
end)
The very last else keeps saying “Expected ', got ‘else’.”
and in my other code, which I shortened down
if not character or (character:FindFirstChild("Humanoid")) and character.Humanoid.Health = 0) then
table.remove(plrs,x)
the = keeps saying “Expected ‘then’ got ‘=’” But there is clearly a then after it, when I move the then to in front, it has more errors.
Thank you, hope we can solve this. ps sorry for the repost, other post got messed up with the code
Check were your connected functions end I see issues with it as you end the PlayerAdded connected function before it even reaches the datastore.
local dataStores = game:GetService("DataStoreService"):GetDataStore("MoneyDataStore")
local defaultCash = 100
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local money = Instance.new("IntValue")
money.Name = "Money"
money.Value = 0
money.Parent = leaderstats
player.CharacterAdded:Connect(function(charter)
charter.Humanoid.WalkSpeed = 16
charter.Humanoid.Died:Connect(function()
-- Whenever someone dies, this event will run/play
if charter.Humanoid and charter.Humanoid:FindFirstChild("creator")then
game.ReplicatedStorage.Status.Value = tostring(charter.Humanoid.creator.Value).. " Killed " ..player.Name
end
if charter:FindFirstChild("GameTag") then
charter.GameTag:Destroy()
end
player:LoadCharter()
end)
end)
--Data Stores
local player_data
pcall(function()
player_data = dataStores:GetAsync(player.UserId.."-Money") --UserID, This saves the data that they may have had
end)
if player_data ~= nil then
--player has saved data,load it in
Money.Value = player_data
else
--new player
bucks.Value = defaultCash
end
end)
I’ve already fixed the code if you chekced the amount of ends you would not have this issue also please make the indenting easier to read instead of just random space’s
if not character or (character:FindFirstChild("Humanoid")) and character.Humanoid.Health == 0 then
table.remove(plrs,x)
An if statement uses the == operator to check a condition. The single equals sign sets a value. I am not sure if this is intentional but it doesn’t look like it. Maybe I just don’t know about something that you are trying to do here.
Any more issues, I’ll be online for a while so feel free to ask.