Issue with '.Changed'

I’m trying to make the script repeat wait(.5) until the boolValue changes, but instead, the first time the value changes, the script doesn’t detect it, for example, when I change the value once, it didn’t detect the change, but when I changed it again, it detected it and continued with the rest of the script. I hope I’m making sense here. Also, there are no errors.

The script:

 local plr = game.Players.LocalPlayer
 local murderer = plr:FindFirstChild("Murderer") --This is a boolValue inside of the player
 repeat wait(.5) until murderer.Changed:wait()

I changed the value using this code:

murderer.Value = not murderer.Value --it just sets it to its opposite value

This code is probably not the greatest but it will work.

local bruh = false
muderer.Changed:Connect(function()
    bruh = true 
end)
repeat wait() until bruh
1 Like

Since the OP used repeat until, i suppose the OP didn’t want to use an function.

1 Like

Thanks, that worked perfectly, but I’m still confused on why my script didn’t work properly. :thinking:

This is redundant and can be simplified to

murderer.Changed:Connect(function()
end)

Need to see the full code.

:WaitForChild() instead of :FindFirstChild() in that case too, or check if the value exists

1 Like
--[[ my original script]] repeat wait(.5)  until murder.Murder.Value == true
 --[[edited version]] repeat wait(.5) murderer.Murderer.Changed:connect(function() bruh = true  end) until bruh == true

The problem with the original code was that I had to change the value twice in order for it to stop repeating (I don’t know what was wrong), and that’s the script after I changed it, also, I did simplify it in my original post, so this might look different.

Instead of this:

repeat wait(.5) murderer.Murderer.Changed:connect(function() bruh = true  end) until bruh == true

Use this:

repeat game:GetService("RunService").Heartbeat:Wait() murderer.Murderer.Changed:Connect(function() bruh = true  end) until bruh == true
1 Like

I would use that, but to be honest, I have no idea what the ‘RunService’ is used for, but I appreciate the help, thanks!

1 Like

RunService can be used for many useful things, but be aware, RunService has an option which some backdoors will use.

And here is the reason to use Heartbeat:

1 Like

As the problem has already been solved, I have a nitpick, couldnt you just eliminate the bruh = true and just do murderer.Changed:Wait() replacing the repeat statement?

This also would be more efficient it seems.

1 Like