Why is my script not working?

Hey everyone! I added something to my script, and it doesn’t work. There is nothing in the output saying that it doesn’t work. The part I added was where it gives someone a point whenever they get a kill.

Could you please help me? This would be great.

Use print statements to see where it stops.

What does this script do? I’m confused.

You need add in the while true do time

while true do
wait(0.1)
– your code
end

What would that do to the script? It just makes it wait a second.

Use the debugger to execute every line of code separately and check if the values of your variables match your expectations, then you can hopefully see where the script suddenly stops. Alternatively, you can add print statements to check whether certain lines of code get reached during execution.

1 Like

That’s the problem. I can’t test out this script because I need to have 2 people in testing studio, which as far as I know, is impossible.

You can run multiple clients using Test > Start Server after selecting a number of clients from the dropdown.

1 Like

Would this create a clone that acts as a player in my game while I’m testing?

This simply opens multiple clients that you can use to test. It’s very helpful if you don’t have a team of people to throw a game at. They will have the names Player1, Player2, ect. You also get separate windows for the server and client, so client-server replication is easier to test.

Image:
image

2 Likes

Ok thanks. I will test this out soon.

But I already know which part of my script isn’t working. It is the part that is supposed to give someone a point when they get a kill. The problem is fixing the bug.

You shouldn’t be making these connections if a player doesn’t exist, that’s likely part of your issue:

            if player then

				character = player.Character

				if not character then
					-- Left the game
					table.remove(plrs,i)
				else
					if character:FindFirstChild("GameTag") then
						-- They are still alive
						print(player.Name.." is still in the game!")
					else
						-- They are dead
						table.remove(plrs,i)
						print(player.Name.." has been removed!")
					end
				end
			else
				table.remove(plrs,i)
				print(player.Name.." has been removed!")
				
				player.CharacterAdded:Connect(function(Character)
					Character.Humanoid.Died:Connect(function(Died)
						local creator = Character.Humanoid:FindFirstChild("creator")
						local leaderstats = creator.Value:FindFirstChild("leaderstats")
						if creator ~= nil and creator.Value ~= nil then
							leaderstats.Points.Value = leaderstats.Points.Value + 1
						end
					end)
				end)
			end

In the bit above, the died event is only connected if the player is removed, which will never happen. You should connect these events in the beginning, in an event like PlayerAdded.