#Bru

1 messages · Page 1 of 1 (latest)

unreal leaf
#
local function pushAndStun(player)
    local character = player.Character
    local hrp = character and character:FindFirstChild("HumanoidRootPart")
    local humanoid = character and character:FindFirstChild("Humanoid")
    if hrp and humanoid then
        -- Push logic
        local direction = (hrp.Position - getHumanoidRootPart(npcModel).Position)
        direction = Vector3.new(direction.X, 0, direction.Z).Unit
        local force = Instance.new("BodyVelocity")
        force.Velocity = direction * 15
        force.MaxForce = Vector3.new(100000, 0, 100000)
        force.Parent = hrp

        local oldWalkSpeed = humanoid.WalkSpeed
        local oldJumpPower = humanoid.JumpPower
        humanoid.WalkSpeed = 0
        humanoid.JumpPower = 0

        -- Push counter logic
        local pushCount = character:FindFirstChild("StudentCouncilPushCount")
        if not pushCount then
            pushCount = Instance.new("NumberValue")
            pushCount.Name = "StudentCouncilPushCount"
            pushCount.Value = 0
            pushCount.Parent = character
        end
        pushCount.Value = pushCount.Value + 1
        if pushCount.Value >= 5 then
            humanoid.Health = 0
            pushCount.Value = 0
        end

        task.wait(0.2)
        force:Destroy()

        -- Keep player grounded after push
        keepPlayerGrounded(hrp)

        task.wait(1.8)
        humanoid.WalkSpeed = oldWalkSpeed
        humanoid.JumpPower = oldJumpPower
    end
end

while true do
    local player = getClosestPlayer()
    if player then
        facePlayerInstantly(player)
        keepNPCGrounded()
        pushAndStun(player)
        task.wait(2)
    else
        keepNPCGrounded()
        task.wait(0.2)
    end
end
#

@abstract fable

abstract fable
#

hi

#

is this what i should put in

unreal leaf
#

this is unsafe

#

if something else sets it before this happens it's still going to set it to oldWalkSpeed

#

and eventually infinite stun

#

you should instead make task.delay

#

and cancel the thread if something else sets it

unreal leaf
abstract fable
unreal leaf
#

no you do this

#

declare a StunThread variable up top

#

and then you do

if StunThread then
  task.cancel(StunThread)
  StunThread = nil
end
StunThread = task.delay(1.8, function()
  humanoid.WalkSpeed = oldWalkSpeed
  humanoid.JumpPower = oldJumpPower
end)
abstract fable
#

how would i declare it- sorry im bad at scripting 😭

unreal leaf
#

this is declaring a variable

#

you want to declare outside of the function

#

at the top of the script

#

local StunThread = nil

#

anything else?

abstract fable
#

so up here?

unreal leaf
#

outside of function

#

at top

abstract fable
#

yeah ik but do i put it where the pink part is

unreal leaf
#

outside of function

#

that's inside the function

abstract fable
unreal leaf
#

declare it here

abstract fable
#

so just local stunthread = player.Character

#

?

unreal leaf
abstract fable
#

oh okay

unreal leaf
#

we are essentially creating a waiting thread and cancelling it if anything run before it

unreal leaf
abstract fable
#

wym

#

no its when u walk into an npc theyre supposed to stun u for 2 seconds

#

and if they stun u 5 times u get killed

unreal leaf
#

who coded this

abstract fable
#

btw after i put local StunThread = nil it still stuns infinitely

unreal leaf
#

you sound like you don't even know what is a variable 🥀

unreal leaf
#

no like

#

learn some scripting a bit

#

a tiny bit

#

or you won't understand what's going on in the slightest

abstract fable
#

where would i put this 😭

if StunThread then
task.cancel(StunThread)
StunThread = nil
end
StunThread = task.delay(1.8, function()
humanoid.WalkSpeed = oldWalkSpeed
humanoid.JumpPower = oldJumpPower
end)

unreal leaf
#

I gave you an oddly similar code to this

#

you know this is the part that stuns right 🥀

#

did chat gpt write this

abstract fable
unreal leaf
#

basically replace this part

abstract fable
#

even task wait or just the humanoids

unreal leaf
#

3 lines

#
if StunThread then
  task.cancel(StunThread)
  StunThread = nil
end
StunThread = task.delay(1.8, function()
  humanoid.WalkSpeed = oldWalkSpeed
  humanoid.JumpPower = oldJumpPower
end)
#

with this

abstract fable
#

kk

#

done

#

still stunned infinitely

unreal leaf
#

your oldWalkSpeed is wrong

#

you can do a print before stunning

#

but I don't wanna fix it rn cuz this is built horribly

abstract fable
#

so what now

unreal leaf
#

find

#

and fix

abstract fable
#

okay

unreal leaf
#

you can do print

#

that's your best friend here

#

I believe oldWalkSpeed is still 0 here