Kick Player When Lives Run Out

If you click the wrong option, a heart turns back using the color3.new and if both of them are black it’s supposed to kick you. im not sure how to make this work. does it need to be a local script?

local players = game:GetService("Players")

players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		local humanoid = character:WaitForChild("Humanoid")

if script.Parent.heart1.ImageColor3 == Color3.new(0, 0, 0) 
	and 
	script.Parent.heart2.ImageColor3 == Color3.new(0, 0, 0) then
			player:Kick("Ran out of lives! Rejoin & try again.")
end
end)
end)

what i mean;

where the script is located:

image

thank you! if you need more info im literally refreshing 100 times a minute

5 Likes

What sort of script is turning the hearts to black?

(Also you don’t need to spam refresh the devforum - it will automatically load any notifications)

2 Likes

its just a regular script! not local, that was my other issue but i found it out on my own.

i hope u can help me mr/ms 372 solutions! ty

1 Like

YOU MADE SHIP TYCOON!?>!?!?!/1 Wow. youre very talented!

Looking at the code, you only seem to be checking the colour of the hearts when the player’s character loads in. If you kill the character and have them respawn (e.g. by pressing esc, then reset), does it correctly kick the player when both hearts are black?

2 Likes

it kicks you when you die, the point of the hearts is if you guess incorrectly twice then you get kicked and have to try again. im sorry i dont really understand what youre saying :frowning:

You should have the code that checks if both hearts are black contained in the same area as the code that actually turns the hearts to black. That way, it will correctly identify when the player should be kicked

1 Like

ohh makes sense, let me try it, thanks !

so would this work?

for me it didnt do anything.

local button = script.Parent -- Assuming the script is a child of the Surface GUI button
local otherButton = script.Parent.Parent.opt3Select

button.MouseButton1Click:Connect(function() 
	print("Clicked")
	local heart1 = button.Parent.heart1
	local heart2 = button.Parent.heart2

	if heart1.ImageColor3 == Color3.new(0, 0, 0) then
		heart2.ImageColor3 = Color3.new(0, 0, 0)
	else
		heart1.ImageColor3 = Color3.new(0, 0, 0)
		
			otherButton.MouseButton1Click:Connect(function()
				print("Clicked#2")
			local heart1 = button.Parent.heart1
			local heart2 = button.Parent.heart2

			if heart1.ImageColor3 == Color3.new(0, 0, 0) then
				heart2.ImageColor3 = Color3.new(0, 0, 0)
			else
				heart1.ImageColor3 = Color3.new(0, 0, 0)

			end
		end)
	end
end)

local players = game:GetService("Players")

heart1 = game.Workspace.puzzlePart.SurfaceGui.heart1
heart2 = game.Workspace.puzzlePart.SurfaceGui.heart2

players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		local humanoid = character:WaitForChild("Humanoid")

		if  heart1.ImageColor3 == Color3.new(0, 0, 0) 
			and 
			heart2.ImageColor3 == Color3.new(0, 0, 0) then
			player:Kick("Ran out of lives! Rejoin & try again.")
		end
	end)
end)

Kinda.
What is the intended size of the servers by the way? Is it meant for a single player at a time?
If not, then you may need to change the code a bit.

yup its singleplayer
yup its singleplayer

Is the player meant to have 2 lives or 3 lives total?

1 Like

2 lives (the 2 hearts in the image)

Based on that, you should be able to add the kicking functionality into this if statement:

if heart1.ImageColor3 == Color3.new(0, 0, 0) then
		heart2.ImageColor3 = Color3.new(0, 0, 0)

(contained within the mouse button 1 click event).

Replace the code I mentioned with this:

if heart1.ImageColor3 == Color3.new(0, 0, 0) then
		heart2.ImageColor3 = Color3.new(0, 0, 0)
        game.Players:GetPlayers()[1]:Kick()

It gets the first player in the game (the only player, in this case), and kicks them.

1 Like

replace that with this code;

if  heart1.ImageColor3 == Color3.new(0, 0, 0) 
			and 
			heart2.ImageColor3 == Color3.new(0, 0, 0) then

or this one;

	if heart1.ImageColor3 == Color3.new(0, 0, 0) then
				heart2.ImageColor3 = Color3.new(0, 0, 0)
			else
				heart1.ImageColor3 = Color3.new(0, 0, 0)
local button = script.Parent -- Assuming the script is a child of the Surface GUI button
local otherButton = script.Parent.Parent.opt3Select

button.MouseButton1Click:Connect(function() 
	print("Clicked")
	local heart1 = button.Parent.heart1
	local heart2 = button.Parent.heart2

	if heart1.ImageColor3 == Color3.new(0, 0, 0) then
		heart2.ImageColor3 = Color3.new(0, 0, 0)
        game.Players:GetPlayers()[1]:Kick()
	else
		heart1.ImageColor3 = Color3.new(0, 0, 0)
		
			otherButton.MouseButton1Click:Connect(function()
				print("Clicked#2")
			local heart1 = button.Parent.heart1
			local heart2 = button.Parent.heart2

			if heart1.ImageColor3 == Color3.new(0, 0, 0) then
				heart2.ImageColor3 = Color3.new(0, 0, 0)
			else
				heart1.ImageColor3 = Color3.new(0, 0, 0)

			end
		end)
	end
end)

Like that ↑

Is it fine if I modify the code significantly to function similarly but just be better?

1 Like

yes of course! as long as it doesnt break haha

weird, it doesnt work. isnt it supposed to announce in the output when the player gets kicked? because right now its not

That don’t look like Color3.new(0, 0, 0) to me. The outline around the text is darker.

if testing==true then
     print("something happen")
end

huh wdym?huh wdym?huh wdym?huh wdym?