Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 4 years ago

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

Log in to vote
0
Answered by
Robowon1 323 Moderation Voter
4 years ago

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)
Ad

Answer this question