Basically, I’m trying to make the monitor have a visual effect
(a rod, connecting the player to the monitor)
And have it flatline when the player dies.
(and speed up when they hit 50)
local heart = script.Parent.Parent
print("Variables done.")
function Attach(hit)
local att = Instance.new("RodConstraint")
local ett = Instance.new("Attachment")
local Playur = hit.Parent
att.Color = BrickColor.Gray()
att.Visible = true
att.Length = 5
att.Attachment0 = script.Parent.Thing
ett.Parent = Playur.RightHand
print("Attachments set")
wait()
att.Attachment1 = ett
end
function Checkup(hit)
local Sure = hit.Parent.Humanoid
print("Checking!")
if Sure.Health <=100 then
heart.Screen.Stable:Play()
heart.Beep1.Transparency = 0
heart.Beep2.Transparency = 1
wait(1)
heart.Screen.Stable:Play()
heart.Beep1.Transparency = 1
heart.Beep2.Transparency = 0
elseif Sure.Health <=50 then
heart.Screen.Fast:Play()
heart.Beep1.Transparency = 0
heart.Beep2.Transparency = 1
wait(.5)
heart.Screen.Fast:Play()
heart.Beep1.Transparency = 1
heart.Beep2.Transparency = 0
elseif Sure.Health <= 0 then
heart.Beep1.Transparency = 1
heart.Beep2.Transparency = 1
heart.Flatline.Transparency = 0
heart.Screen.Flatline:Play()
end
end
script.Parent.Touched:Connect(Attach)
script.Parent.Touched:Connect(Checkup)
I also cannot get the beeping to loop, so if you have any suggestions please tell me.
All of the prints work fine, The only error i get is when it hits an accessory which is not a problem.
Everything seems good so far! It’s pretty simple to loop something, but with this is mind, you have to fix your if statements first. It’s good practice to keep ranges in the if statements. Right now you have:
if Sure.Health <= 100 then --> less or equal to 100
elseif Sure.Health <= 50 then --> less or equal to 50
elseif Sure.Health <= 0 then --> less or equal to 0
end
So right now your script is is reading if everything is less than 100. To fix this, we need to add ranges like this.
if Sure.Health <= 100 and Sure.Health > 50 then --> less or equal to 100, greater than 50 (51-100)
elseif Sure.Health <= 50 and Sure.Health > 0 then --> less or equal to 50, greater than 0 (1-50)
elseif Sure.Health <= 0 then --> less or equal to 0
end
This fixes the range issue, now we’re gonna loop it!
function Checkup(hit)
local Sure = hit.Parent.Humanoid
print("Checking!")
while true do
if Sure.Health <= 100 and Sure.Health > 50 then --> less or equal to 100 and greater than 50 (51-100)
elseif Sure.Health <= 50 and Sure.Health > 0 then --> less or equal to 50 and greater than 0 (1-50)
elseif Sure.Health <= 0 then --> less or equal to 0
end
end
end
Note, you need to add a break in the loop of the player disconnects from the heart rate machine.
I haven’t tested this but I hope it works! If you have any further questions let me know, If this works please mark this as a solution.
I think i figured it out, With every individual part of the player that touches the connector part, it creates a new loop every time, causing the overlap, I tried to do a debounce for it bit it didn’t work.
I’m glad it worked! If you get stuck on the rod constraints, I’d suggest making a new thread about it since your OP has no mention of it. Happy developing!