Errors with the Code

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

1 Like

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)
1 Like

Can you go a bit more into detail. :slight_smile: … As in what should I change it to, etc.

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

1 Like

Should I just paste your code over to my code?

Yes, and it will work even though all I did was fix some issues with the ends.
May I recommend you actually read developer.roblox.com

1 Like

I pasted your code over to my code… It still says an error on the else.

I noticed that and fixed it you may have the old edit on your clipboard.

1 Like

Thank you for this. Now can you provide help with the other script. :wink:

And what might that be plus my computer is about to die. I can help later. I recommend you make a new thread though as its a diffrent script.

if not character or (character:FindFirstChild("Humanoid")) and character.Humanoid.Health = 0) then
					table.remove(plrs,x)

Says "expected ‘then’, got ‘=’

A few sytax errors in this snippet. Try:

    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.

if not character or (character:FindFirstChild("Humanoid")) and character.Humanoid.Health == 0) then

Can I put 2 of your posts as solved?

Negative only one. I belive atleast I’m not 100% sure.

Wait one more error… expected near 'end"

just add an end after table.remove(plrs, x)

So last time I saw you did
if … then

end
else

end
–This is not right you need to do
if … then

else

end

Where would I locate that in my code?

Were you put that else look above it for the first end and remove it.