Hello, devs! I am making a GUI that changes it when it detects the player is dead. The player is killed after a RemoteEvent is fired then the GUI detects the change and changes itself. It works but the problem I have is that this only fires once. After that, it changes nothing. Here is the script. Thank you and support is appreciated!
local player = game.Players.LocalPlayer
player.Character:WaitForChild("Humanoid")
local humanoid = player.Character.Humanoid
local lives = player.Lives
humanoid.Died:Connect(function()
print(player)
if player then
game.ReplicatedStorage.PlayerDied:FireServer(player)
print("Fired!")
else
return nil
end
end)
script.Parent.Parent.MenuGui.Frame.PlayButton.MouseButton1Click:Connect(function()
wait(0.216)
script.Parent.Live1.Visible = true
script.Parent.Live2.Visible = true
script.Parent.Live3.Visible = true
print("Lives visible!")
end)
lives:GetPropertyChangedSignal("Value"):Connect(function()
if lives.Value == 2 then
script.Parent.Live3.Image = "rbxassetid://7061951219"
print("Changed!")
end
if lives.Value == 1 then
script.Parent.Live2.Image = "rbxassetid://7061951219"
print("Changed!")
end
if lives.Value == 0 then
script.Parent.Live1.Image = "rbxassetid://7061951219"
print("Changed!")
end
end)
What I mean is when the player dies, a RemoteEvent is fired. However, it only fires when a player dies one time. When the player dies again or multiple times, nothing happens with no errors.
First, try changing the script to this and let me know if it works.
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:wait()
local humanoid = player.Character:WaitForChild("Humanoid")
local lives = player.Lives
humanoid.Died:Connect(function()
print(player)
if player then
game.ReplicatedStorage.PlayerDied:FireServer(player)
print("Fired!")
else
return nil
end
end)
script.Parent.Parent.MenuGui.Frame.PlayButton.MouseButton1Click:Connect(function()
wait(0.216)
script.Parent.Live1.Visible = true
script.Parent.Live2.Visible = true
script.Parent.Live3.Visible = true
print("Lives visible!")
end)
lives:GetPropertyChangedSignal("Value"):Connect(function()
if lives.Value == 2 then
script.Parent.Live3.Image = "rbxassetid://7061951219"
print("Changed!")
end
if lives.Value == 1 then
script.Parent.Live2.Image = "rbxassetid://7061951219"
print("Changed!")
end
if lives.Value == 0 then
script.Parent.Live1.Image = "rbxassetid://7061951219"
print("Changed!")
end
end)
Then unfortunately you’ll have to either move the location of the script to be where it doesn’t break, or add scripts to the GUI that you want invisible and set them to be invisible. There might be another way, but if there is I don’t know of it