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)
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?
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
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
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.
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?