#connections

96 messages · Page 1 of 1 (latest)

drowsy moat
#

how do i make a connection run once, but disable it so it never runs again on that script?

#
local connection
connection = script.Parent.Humanoid:GetPropertyChangedSignal("Health"):Connect(function()
    if(script.Parent.Humanoid.Health < 2500) then
        script.Parent.Head.ParticleEmitter.Enabled = true
        halfhp:Play()
        script.Parent["Man Screaming"]:Play()
        D = 2
    end
    connection:Disconnect()
end)

doesnt work

#

tried putting connection:Disconnect() after ```lua
end)

wheat cypress
drowsy moat
#

studio** You are now Level 2! **studio

#

after the humanoid is below 2500 hp, it doesnt run

#

the connection is outside any functions

wheat cypress
#

And this is a script inside the characters model right?

drowsy moat
#

yes

#

it is

wheat cypress
#

That is probably where it's disconnecting

drowsy moat
#

so what should i do

wheat cypress
#

What are you trying to do exactly?

drowsy moat
#

when the health changes to below 50% (2500 hp), it should start the particles, play the audio, and play the animation

#

not sure what i did wrong there

clear sky
#

🤭

wheat cypress
drowsy moat
wheat cypress
drowsy moat
#

lemme check again

clear sky
drowsy moat
#

is it bc im assigning the connection to the connection variable and its not running?

wheat cypress
#

That shouldn't be a problem, I see it done all the time

#

Let me try writing it out myself rq

drowsy moat
#

kk

wheat cypress
#

Does the formatting work on mobile

drowsy moat
#

its below 2500 hp but still doesnt do the thing

clear sky
#

no

wheat cypress
#

Mk

drowsy moat
#

halfhp:Play() is playing the animation

#

jsyk

wheat cypress
#

local char = script.Parent; local hum = char:WaitForChild("Humanoid")
local halfhp -- don't know what this is
local con = hum.HealthChanged:Connect(function()
if hum.Health < hum.Health/2 then
print("Under half")
con:Disconnect()
end
end)

OK I kinda skipped out on the content part but I just want to see if this prints before I write the rest out

drowsy moat
#

studio** You are now Level 1! **studio

#

hm wait

#
local connection
connection = script.Parent.Humanoid:GetPropertyChangedSignal("Health"):Connect(function()
    if(script.Parent.Humanoid.Health < script.Parent.Humanoid.Health / 2) then
        script.Parent.Head.ParticleEmitter.Enabled = true
        halfhp:Play()
        script.Parent["Man Screaming"]:Play()
        D = 2
        print("Under half")

    end
    connection:Disconnect()
end)
#

like that?

#

lemme try now

#

nope doesnt print "Under half"

clear sky
#

whats the D = 2

drowsy moat
#

delay between attacks

clear sky
#

but for what

wheat cypress
drowsy moat
#

after half hp the attacks would be faster

clear sky
#

hes disconnecting it

drowsy moat
wheat cypress
#

You can probs copy and paste what I sent

#

It should fornst

#

Format

drowsy moat
#

it formatted but now it shows this

clear sky
#

it'll format

drowsy moat
#

i deleted the halfhp variable since that doesnt matter after that

#

i lack the sense called "logic" in the mush called a "brain"

wheat cypress
#

Ah

clear sky
#

you do

drowsy moat
#

do yall need my entire script

clear sky
#

send it rq

#

like the screenshot

drowsy moat
#

studio** You are now Level 3! **studio

#

its a bad way to do what i did but here

#

its 162 lines

clear sky
drowsy moat
#

i cant screenshot all of it

wheat cypress
# drowsy moat

local char = script.Parent; local hum = char:WaitForChild("Humanoid")
local halfhp -- don't know what this is
local con
con = hum.HealthChanged:Connect(function()
if hum.Health < hum.Health/2 then
print("Under half")
con:Disconnect()
end
end)

#

Aha

drowsy moat
#

ill copy paste this

#

now lemme try

#

nothing was printed

clear sky
#

cuz hp aint 2500 or less

drowsy moat
#

it was

#

max hp is 5000 and i hit it until it was clearly below half

#

nothing got printed

wheat cypress
#

Interesting

#

My go to strategy is to just add a debug message every line until I find the problem but that's probably not best

drowsy moat
#

is HealthChanged a function?

drowsy moat
#

lemme debug each line one by one

#

🗿

wheat cypress
drowsy moat
#

oh yeah it was

#

it autocompleted it

#

but i still dont get whats wrong

wheat cypress
#

Just add a debug between every line of the code I sent for now and find the exact point it breaks, that's probably the most effective way even if it's time consuming

drowsy moat
#

the rest of the scripts works jsyk

#

so its probably just that part

wheat cypress
#

Which is why you only need to debug that part

drowsy moat
#

ye and it seems normal

#

i dont see why it wouldnt work