Hello everyone! I’m in mid of making a stealth game tutorial, here on devforum dot com.
I’m trying to make the detection bar, and I’ve managed to make it go up when they are in detection conditions flawlessly. Now, I have to make it go down once they’re not, and I’m having quite a hard time.
This is the best result I’ve got:
Here’s the script: (I edited out the rest of the script)
local function onRenderStepped(dt: number) -- detection bar part if isDetecting then -- if detecting if crouching then detectionRate = distance / 2 else detectionRate = distance / 100 end -- add our detection rate to the current detection + clamping it detection = math.clamp(detection + detectionRate,0,100) if not detectionBarGui.Enabled then -- if our gui is not showing up, make it show detectionBarGui.Enabled = true end if detection >= maxDetection then -- if we're at at max detection detected = true -- TODO make our enemies react else -- resize our detection bar, dividing the detection by the max detection detectionBarGuiBar.Size = UDim2.new(1,0,-(detection/maxDetection),0) end else -- we are not being detected if detectionBarGuiBar.Size ~= UDim2.new(1,0,0,0) then detection = math.clamp(detection - detectionRate,0,100) print(detection) -- making our bar go down detectionBarGuiBar.Size = UDim2.new(1,0,detection/maxDetection,0) elseif detectionBarGui.Enabled then -- if our gui is showing, make it not show anymore detectionBarGui.Enabled = false end end end
distanceis the distance between the player and dummy;
crouchingis wherever the player is crouching or not;
I’d appreciate any help!