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
#Bru
1 messages · Page 1 of 1 (latest)
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
this is your code
?
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)
how would i declare it- sorry im bad at scripting 😭
this is declaring a variable
you want to declare outside of the function
at the top of the script
local StunThread = nil
anything else?
so up here?
yeah ik but do i put it where the pink part is
no
outside of function
that's inside the function
btw this is the full script
declare it here
@abstract fable
oh okay
we are essentially creating a waiting thread and cancelling it if anything run before it
I hope this is not a characterscript
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
dawg 🥀
who coded this
btw after i put local StunThread = nil it still stuns infinitely
you sound like you don't even know what is a variable 🥀
@abstract fable did you put this aswell
no like
learn some scripting a bit
a tiny bit
or you won't understand what's going on in the slightest
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)
just guess
I gave you an oddly similar code to this
you know this is the part that stuns right 🥀
did chat gpt write this
ik
even task wait or just the humanoids
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
I know what the problem is
your oldWalkSpeed is wrong
you can do a print before stunning
but I don't wanna fix it rn cuz this is built horribly
so what now
okay