Humanoid not changing state properly (Taser script)

Hello, I am trying to make a simple taser.

The way I am doing this is by using ray casting. The ray begins from the position of the emitter situated at the front of the taser and is directed towards the player mouse. Whenever the ray hits character with a humanoid, It inserts a script into the humanoid (a normal script for NPCs and a localscript for a player) which changes its state to Enum.HumanoidStateType.Physics. After five seconds it changes it’s state to Enum.HumanoidStateType.GettingUp.

However the issue I am facing is that it works perfectly for the player, but the humanoid does not change its state properly for NPCs.
Either the stunning does not happen properly or the player never gets up.

Here is the clip:
Stun Glitch.wmv (2.7 MB)

Here is the NPC stun script:

-- TASER NPC STUN CHIP --
-- Humanoid object
local humanoid = script.Parent

-- Functions
local function HumanoidCheck()
    if humanoid.ClassName ~= "Humanoid" then
        game:GetService("Debris"):AddItem(script, 0.01)
    end
end

local function StunPlayer()
    if humanoid:GetState() ~= Enum.HumanoidStateType.Physics or humanoid:GetState() ~= Enum.HumanoidStateType.GettingUp then
        humanoid:ChangeState(Enum.HumanoidStateType.Physics)
        wait(5)
        humanoid:ChangeState(Enum.HumanoidStateType.GettingUp)
    end
    game:GetService("Debris"):AddItem(script, 0.01)
end

-- Applying functions
HumanoidCheck()
StunPlayer()

I have no idea why this happens…
Any help would be highly appreciated

Thank You!

2 Likes

Did you try it on a real player? It could possibly be that its an NPC and not a real player.

Yes i have tried it.
It works perfectly.

Is your taser animation intended for R6 or R15? Because i’m pretty sure that zombie model is R6.

Is the script in the NPC a LocalScript? if it is then change it into a ServerScripts since the LocalScript won’t run

Actually I am making an R15 game but does the Humanoid:ChangeState() really depend on which avatar type we are using?

For the player I am using a localscript (since Humanoid:ChangeState() only works in a localscript for a player character), and for the NPC it is a server script itself.

It does if you dont have an animation for R6 did you make one?

I am not using any animation when stunning the player…
all it just does is to change its state to ‘physics’ so that the humanoid cannot apply any force on itself.

Also, I have tried it with an R15 dummy as well…
It produces the same result.

weird maybe it has something to do with the script and NPC’s,

Yes I agree…I have tried it with several NPCs, but it always work the same way…

Here is another clip (with R15 NPC)…
Stun-glitch-2

Is there any better way to stun a character apart from changing the humanoid state?

It works initially, but after some shots either the player does not stun properly (or even sometimes never stuns at all) or never gets up…

Yeah I dont know maybe someone else does.

Oh I see…
Thanks anyway!

Sorry I couldnt help much but your welcome! :slight_smile:

You could just set walkspeed and jumppower to 0 and rotate the primary part of the character 90 - 120 degrees so they fall rigid. This might work better with npc’s.

It’s not smooth but still it works
When I flip the NPCs HumanoidRootPart the humanoid automatically changes its state to 'FallingDown'

But I don’t know why this does not work properly

humanoid:ChangeState(Enum.HumanoidStateType.FallingDown)
humanoid:SetStateEnabled(Enum.HumanoidStateType.GettingUp, false)

but this works

humanoid.RootPart.CFrame = CFrame.new(humanoid.RootPart.Position) * CFrame.Angles(-- Whatever angle --)
humanoid:SetStateEnabled(Enum.HumanoidStateType.GettingUp, false)

Maybe an engine bug…not sure.

Thanks a lot!

2 Likes