Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

I believe I accidentally messed up something with my leaderstats script. Help?

Hello,

I'm making a "Stay Alive and Steal Time" game on ROBLOX, and I believe I messed up something with the "ends". Could I get some help correcting whatever error there is? Here is the script:

local DataStoreService = game:GetService("DataStoreService")
local Datastore = DataStoreService:GetDataStore("TimeStatistics")

game.Players.PlayerAdded:Connect(function(Player)
	
	local leaderstats_folder = Instance.new("Folder", Player)
	leaderstats_folder.Name = "leaderstats"
	
	local Top_Time = Instance.new("IntValue", leaderstats_folder)
	Top_Time.Name = "TopTime"
	Top_Time.Value = 0
	
	local Time_Alive = Instance.new("IntValue", leaderstats_folder)
	Time_Alive.Name = "TimeAlive"
	Time_Alive.Value = 0
	
	local Kills = Instance.new("IntValue", leaderstats_folder)
	Kills.Name = "Kills"
	Kills.Value = 0

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

		player.CharacterAdded:Connect(function(character)
			local humanoid = character:FindFirstChild("Humanoid")

			humanoid.Died:Connect(function(died)
				local tag = humanoid:FindFirstChild("creator")
				local killer = tag.Value
				if tag and killer then
					killer.leaderstats:FindFirstChild("Kills").Value = killer.leaderstats:FindFirstChild("Kills").Value + 1
	
	local key = Player.UserId .. "-TimeStatistics"
	local storeditems = {0,0}

	local Succes, ErrorMessage = pcall(function()
		storeditems = Datastore:GetAsync(key)
	end)

	if Succes then
		print("data successfully recieved for " .. Player.UserId)
		if storeditems then
			Top_Time.Value = storeditems[1]
			Time_Alive.Value = storeditems[2]
			Kills.Value = storeditems[3]
		else
			local items_to_store = {Top_Time.Value ,Time_Alive.Value, Kills.Value} 
			Datastore:SetAsync(key, items_to_store)
		end
	else
		print("something went wrong while loading data for " .. Player.UserId)
	end

				end
			end)
		end)
	end)
end)

3 comments

0

Adding on to this, I was trying to combine two scripts. That's why I believe that I messed up the ends.

0

Could you elaborate? what comes out in output when you try to run this?

0

I FIGURED IT OUT, SORRY TO BOTHER!!!

1 answer

Try removing the second player added event...it is practically useless since you already have a line that functions when a player joins

2 comments

0

Didn't work, I believe it is an issue with the "end"s and "end)"s.

0

Oh ok im glad you figured out the problem

This discussion is preserved as it was. New answers, comments, and votes are closed.