Taser Scripting Support

So, when testing and clicking the character I wish to tase. It returns an error within the developer panel, this error is as follows.

Players.RenderedPhysics.Backpack.Taser.TaserSystem.ServerHandler:9: table index is nil

Overview
image

LocalScript

local Configuration = require(script.Parent)
local Player = game:GetService("Players").LocalPlayer
local Mouse = Player:GetMouse()
local Taser = script.Parent.Parent
local Event = script.Parent:WaitForChild("TaserEvent")
local MaxDistance = 15
local AnimationReload = script.Parent.ReloadAnimation
local AnimationTaser = script.Parent.TaserAnimation
local PlayingAnimationTaser = Player.Character.Humanoid:LoadAnimation(AnimationTaser)
local PlayingAnimationReload = Player.Character.Humanoid:LoadAnimation(AnimationReload)

Taser.Equipped:Connect(function()
	PlayingAnimationTaser:Play()
end)

Taser.Unequipped:Connect(function()
	PlayingAnimationTaser:Stop()
	PlayingAnimationReload:Stop()
end)


Taser.Activated:Connect(function()
	local Target = Mouse.Target
	if Target and Target.Parent and Target.Parent:FindFirstChild("Humanoid") then
		if Target.Parent.Name ~= Player.Name then
			local TaserPosition = Taser.Handle.Position
			local TargetPosition = Target.Position
			local DistanceFromHuman = (TaserPosition - TargetPosition).Magnitude

			if DistanceFromHuman <= MaxDistance then
				if script.Parent.CurrentAmmo.Value > 0 then
					Event:FireServer("Shock", {PlayerToStun = Target.Parent})
				end
			end
		end
	end
end)

Mouse.KeyDown:Connect(function(KeyPressed)
	if KeyPressed == "r" and not game:GetService("UserInputService"):GetFocusedTextBox() then
		if script.Parent.CurrentAmmo.Value == 0 then
			PlayingAnimationReload:Play()
			wait(2)
			if Taser.Parent:FindFirstChild("Humanoid") then
				Event:FireServer("Reload", Configuration.MaxAmmo)
			end
		end
	end
end)

ServerScript

local Event = script.Parent.TaserEvent
local DebounceTable = {}

Event.OnServerEvent:Connect(function(Player, Type, Data)
	if Type == "Shock" then
		if script.Parent.CurrentAmmo.Value > 0 then
			local PartToStun = Data.HumanoidRootPart
			if not DebounceTable[PartToStun] then
				DebounceTable[PartToStun] = true
				local Character = PartToStun.Parent
				local Humanoid = Character:FindFirstChild("Humanoid")
				if Humanoid then
					local backwardForce = -PartToStun.CFrame.lookVector * 500
					Humanoid:ApplyImpulse(backwardForce)
				end
				wait(2)
				DebounceTable[PartToStun] = false
			end
		end
	elseif Type == "Reload" then
		script.Parent.CurrentAmmo.Value = Data
	end
end)

What I am trying to do, is make the player trip backwards once the event was fired.

4 Likes

It seems like the value called “PartToStun”, is not apart of the Debounce table.

Maybe add “PartToStun” to the debounce table and see what happens?

Like this:

local DebounceTable = {
PartToStun = false
}
2 Likes

I have tried this, it returns the same error.

1 Like

Maybe instead of using a table for the debounce, why not just use a regular bool value?

local PartToStun = false

I changed it to this,

local Event = script.Parent.TaserEvent
local Debounce = false

Event.OnServerEvent:Connect(function(Player, Type, Data)
	if Type == "Shock" then
		if script.Parent.CurrentAmmo.Value > 0 then
			local PartToStun = Data.HumanoidRootPart
			if Debounce ~= false then
				Debounce = true
				local Character = PartToStun.Parent
				local Humanoid = Character:FindFirstChild("Humanoid")
				if Humanoid then
					local backwardForce = -PartToStun.CFrame.lookVector * 500
					Humanoid:ApplyImpulse(backwardForce)
				end
				wait(2)
				Debounce = false
			end
		end
	elseif Type == "Reload" then
		script.Parent.CurrentAmmo.Value = Data
	end
end)

but now nothing happens.

could it be that im testing this on an NPC?

Change this line from:

if Debounce ~= false then

to

if Debounce ~= true then

and see what happens

Thanks for that, should’ve realised quicker…

Now getting past that, it is not returning the error

ApplyImpulse is not a valid member of Humanoid "Workspace.AlreadyPro.Humanoid"

I have replaced my script, now the character only moves back about 0.00002 studs. I want them to completely fall over backwards.

local Event = script.Parent.TaserEvent
local Debounce = false

Event.OnServerEvent:Connect(function(Player, Type, Data)
	if Type == "Shock" then
		if script.Parent.CurrentAmmo.Value > 0 then
			local PartToStun = Data.HumanoidRootPart
			if Debounce ~= true then
				Debounce = true
				local Character = PartToStun.Parent
				local rootpart = Character:FindFirstChild("HumanoidRootPart")
				if rootpart then
					local backwardForce = -PartToStun.CFrame.lookVector * 50 
					rootpart:ApplyImpulse(backwardForce)
				end
				wait(2)
				Debounce = false
			end
		end
	elseif Type == "Reload" then
		script.Parent.CurrentAmmo.Value = Data
	end
end)

put them in platform stand?

(remove30charrule)

I don’t understand this, sorry.

Humanoid:ChangeState(14)
platformstand is where the player has no control of their character, like when you travel at very fast speeds and the character goes in a flinging motion, all the limbs look like they get stuck to each other

This doesn’t really do anything either, it just lowers the character under the map by the smallest bit and drags them back.

I was able to work this out, my script is currently;

local Event = script.Parent.TaserEvent

Event.OnServerEvent:Connect(function(Player, Type, Data)
	if Type == "Shock" then
		if script.Parent.CurrentAmmo.Value > 0 then
			local PartToStun = Data.HumanoidRootPart
			local bodyForce = Instance.new("BodyForce")
			bodyForce.Force = Vector3.new(0, 1000, 0)
			bodyForce.Parent = PartToStun
			PartToStun.Parent.Humanoid.PlatformStand = true
			wait(5)
			bodyForce:Destroy()
			PartToStun.Parent.Humanoid.PlatformStand = false
		end
	elseif Type == "Reload" then
		script.Parent.CurrentAmmo.Value = Data
	end
end)

The character’s legs fall through the ground, but does not face plant the floor unless you walk over it. How do I do this?

add the bodyforce after you set it to platformstand

This makes absolutely no difference.

try Humanoid:ChangeState(0)
Falling down - when the player has been tripped and will get up automatically

This still does not show any result. Is there any way I can make something that weighs the character down on the front side?

i can only think of making a part behind the char and pushing it

I tried duplicating the head and resizing it, which worked just fine. However the character gets pushed backwards slowly.