Hello developers,
I recently released a slapping system for my game, but players been reporting that they randomly die when they were slapped by a glove, can anyone help me? This is urgent, since I have to keep putting a manual respawn system for the game. (because something breaks whenever a player dies)
ServerScript in tool
local glove = script.Parent.Parent.Parent.Glove
local hand = script.Parent.Parent.Hand
local slap = script.Parent.Parent.Slap
local playerslapped = game.ReplicatedStorage.Events.Extras:WaitForChild("PlayerSlapped")
local ragdollmodule = require(game.ReplicatedStorage.RagdollScript)
local stoodup = nil
playerslapped.OnServerEvent:Connect(function(player, targetedplayer, humanoid, althit)
if not slap.IsPlaying then
slap:Play()
end
local targetHumanoid = targetedplayer:WaitForChild("HumanoidRootPart")
local playerHumanoid = player.Character:WaitForChild("HumanoidRootPart")
if targetHumanoid and playerHumanoid then
local targetedplayerinstance = game:GetService("Players"):GetPlayerFromCharacter(targetedplayer)
local velocity = Instance.new("BodyVelocity",targetedplayer.HumanoidRootPart)
velocity.MaxForce = Vector3.new(4,4,4) * math.huge
local dir = (targetedplayer.HumanoidRootPart.CFrame.Position - player.Character.HumanoidRootPart.Position).Unit
velocity.Velocity = (dir + Vector3.new(0,0.7,0)).Unit *script.Parent.GloveStatsConfig.Power.Value
local rot = Instance.new("BodyAngularVelocity",targetedplayer.HumanoidRootPart)
rot.AngularVelocity = Vector3.new(1,2,1) * math.pi *5
rot.MaxTorque = Vector3.new(2,5,2) *math.huge
rot.P = 6000
targetedplayer.Humanoid:ChangeState(Enum.HumanoidStateType.Physics)
ragdollmodule.Ragdoll(targetedplayer, targetedplayerinstance)
game:GetService("Debris"):AddItem(velocity, 0.7)
game:GetService("Debris"):AddItem(rot,0.7)
task.wait(3)
ragdollmodule.Stand(targetedplayer, targetedplayerinstance, targetedplayer.Humanoid)
targetedplayer.Humanoid:ChangeState(Enum.HumanoidStateType.GettingUp)
end
end)
Ragdoll Module script
local RagdollFunctions = {}
RagdollFunctions.Ragdoll = function(char, player)
if player ~= nil then
game.ReplicatedStorage.Events.Extras.RagdollEvent:FireClient(player, "Ragdoll")
end
char.Humanoid.JumpPower = 0
for _, v in pairs(char:GetDescendants()) do
if v:IsA("BasePart") and v.Name == "Head" then
local weld = Instance.new("Weld")
weld.Part0 = char.HumanoidRootPart
weld.Part1 = v
weld.C0 = char.HumanoidRootPart.CFrame:inverse()
weld.C1 = v.CFrame:Inverse()
weld.Parent = char.HumanoidRootPart
weld.Name = "RagdollWeld"
end
if v:IsA("Motor6D") then
local attachment1 = Instance.new("Attachment")
local attachment0 = Instance.new("Attachment")
attachment0.Name = "SAttachment0"
attachment1.Name = "SAttachment1"
attachment0.CFrame = v.C0
attachment1.CFrame = v.C1
attachment0.Parent = v.Part0
attachment1.Parent = v.Part1
local constraint = Instance.new("BallSocketConstraint")
constraint.Attachment0 = attachment0
constraint.Attachment1 = attachment1
constraint.Parent = v.Part0
v.Part0 = nil
end
end
end
function createMotor6D()
local motor6D = Instance.new("Motor6D")
motor6D.MaxVelocity = 0.1
return motor6D
end
RagdollFunctions.Stand = function(char, player, humanoid)
char.Humanoid.JumpPower = 50
for _, v in pairs(char:GetDescendants()) do
if v.Name == "SAttachment0" then
v:Destroy()
elseif v.Name == "SAttachment1" then
v:Destroy()
elseif v.Name == "RagdollWeld" then
v:Destroy()
elseif v:IsA("BallSocketConstraint") then
v:Destroy()
end
end
for _, v in pairs(char:GetDescendants()) do
if v:IsA("Motor6D") then
v.Part0 = v.Parent
end
end
if player ~= nil then
game.ReplicatedStorage.Events.Extras.RagdollEvent:FireClient(player, "Stand")
end
end
return RagdollFunctions
Thanks!