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