OH it’s a serverscript, i just assumed it was a localscript because I use those more.
repeat wait() until
shouldn’t be used for something like this, I get it seems simple but using wait() can really slow down your game.
If you need to detect a value change, use .Changed
Instead of:
repeat
wait()
until Value2.Value == true
Do:
local HasChanged = false
Value2.Changed:Connect(function(Property)
if Property == "Value" then
if Value2.Value == true and not HasChanged then
HasChanged = true
-- Do code here
end
end
end)
Alternatively, you could use :GetPropertyChangedSignal()
but either way works.
Instances inheriting from ValueBase each have special Changed events that only fire when their value changes so it’s functionally equivalent to using GetPropertyChangedSignal for other instances. The Changed events will also fire with the new value which is more convenient if you want to check directly. In the context of an xValue object, use Changed.
value2.Changed:Connect(function (newValue)
-- Do things here. Changed only fires when the Value is changed.
end)
Ohh okay, I didn’t realise that the changed only fires for the value, thank you!
Instead of making a new thread about the same issue, check the answers in this one.
Try doing
while task.wait(0.05) do
if game.StarterPlayer.StarterCharacterScripts.CheckIfPlayerIsInArea2.Value == true then
break
end
end
Does this work?
the other thread for the same problem was made before this one but only got 1 answer that didnt work
no, i think it might be more than the one line thats causing it to stop
to fix this what do I add to this code? before the “if and” do I put another “if” asking if it is not the monster?
would this work (head monster as in the monster’s head):
if e.name ~= "HeadMonster" then
The error is from TutorialMonster not having a child called “CheckIfPlayerIsInArea” when a .
operator is used (ex: instance.name
). You’d either need to check if it exists or wait for it to exist. If it never exists, then you’re problem is from much more than the code you shared.
I’d need more info to debug your problem.
can I instead just copy CheckIfPlayerIsInArea to the tutorialMonster
Why doesn’t you tutorial monster just already have that BoolValue inside of it?
I’m adding my own scripts on top of what the tutorial teaches
I added the bool to the tutorial monster and it fixes the red error but this orange one still remains:
Infinite yield possible on 'Workspace.tutorialMonster:WaitForChild("Humanoid")'
Someone said this is 'cause the humanoid is called Zombie but if I change it to Humanoid it says
Zombie is not a valid member of Model "Workspace.tutorialMonster"
Replace :WaitForChild("Humanoid")
with :WaitForChild("Zombie")
The first error means that that line of code, :WaitForChild("Humanoid")
might wait forever for a child named “Humanoid”. Your Humanoid is named “Zombie” so you’ll need to use :WaitForChild("Zombie")
to get it.
the thing is the script is actually trying to check for a player inside the area but it also detects the monster as a player so if I change humanoid to zombie it won’t work either
also, the error occurs when the monster leaves the area
Is it working properly without the repeat until
?
Yes it is working without the repeat until
UPDATE: It seems to work before I get this error:
Infinite yield possible on 'Workspace.tutorialMonster:WaitForChild("Humanoid")' - Studio
Anyone know how to fix this? My guess is that it’s trying to damage it’s own Humanoid which is called Zombie
--Responsible for regening a player's humanoid's health
-- declarations
local Figure = script.Parent
local Head = Figure:WaitForChild("Head")
local Humanoid = Figure:WaitForChild("Humanoid")
local regening = false
-- regeneration
function regenHealth()
if regening then return end
regening = true
while Humanoid.Health < Humanoid.MaxHealth do
local s = wait(1)
local health = Humanoid.Health
if health > .1 and health < Humanoid.MaxHealth then
local newHealthDelta = 0.01 * s * Humanoid.MaxHealth
health = health + newHealthDelta
Humanoid.Health = math.min(health,Humanoid.MaxHealth)
else
game.StarterPlayer.StarterCharacterScripts.Jumpscare.Value = true
end
end
if Humanoid.Health > Humanoid.MaxHealth then
Humanoid.Health = Humanoid.MaxHealth
end
regening = false
end
Humanoid.HealthChanged:connect(regenHealth)
If its own humanoid is named “Zombie”, then you need to change the name of the Humanoid to “Zombie”