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.
-- 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
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.
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.
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.