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

Why is my local script working the first time but after they die it stops?

This local script is located in StarterPlayerScripts there is no error message that appears too. I am confused on why this local script works the first time but not after the person dies?

repeat wait() until game.Players.LocalPlayer.Character
print("safdsjhfl;ksajd;lfkjasd")

if game.Players.LocalPlayer.Character.Beep.Value == 0 then
		game.Players.LocalPlayer.PlayerGui.ScreenGui.Dave.Grenade.Text = "x 2"
		end
game.Players.LocalPlayer.Character.Beep.Changed:Connect(function()
	print("why?")
	repeat wait() until game.Players.LocalPlayer.Character
		if game.Players.LocalPlayer.Character.Beep.Value == 1 then
	game.Players.LocalPlayer.PlayerGui.ScreenGui.Dave.Grenade.Text = "x 1"
	 else if game.Players.LocalPlayer.Character.Beep.Value == 2 then
		game.Players.LocalPlayer.PlayerGui.ScreenGui.Dave.Grenade.Text = "x 0"

	end
		
end
end)

1 answer

✓ Accepted answer

Your repeat until loop is waiting for the character, and when the character ~= nil it executes the code below. The problem is though that it will only repeat once though.

Fix:

repeat wait() until game.Players.LocalPlayer.Character
print("safdsjhfl;ksajd;lfkjasd")
while true do

if game.Players.LocalPlayer.Character.Beep.Value == 0 then
        game.Players.LocalPlayer.PlayerGui.ScreenGui.Dave.Grenade.Text = "x 2"
        end
game.Players.LocalPlayer.Character.Beep.Changed:Connect(function()
    print("why?")
    repeat wait() until game.Players.LocalPlayer.Character
        if game.Players.LocalPlayer.Character.Beep.Value == 1 then
    game.Players.LocalPlayer.PlayerGui.ScreenGui.Dave.Grenade.Text = "x 1"
     else if game.Players.LocalPlayer.Character.Beep.Value == 2 then
        game.Players.LocalPlayer.PlayerGui.ScreenGui.Dave.Grenade.Text = "x 0"
end
    end

end
end)

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