I’m trying to make a simple push script, but every time I try to fire the function to ragdoll the player it always fires twice or more, causing the player to not actually ragdoll, but simply change it’s state
Local Script
local request_push = game:GetService("ReplicatedStorage"):WaitForChild("ragdoll_request")
local uis = game:GetService("UserInputService")
local ts = game:GetService("TweenService")
local debounce = false
local countdown = 5
local chr = script.Parent.Parent
local animator = chr:FindFirstChildOfClass("Humanoid"):FindFirstChildOfClass("Animator")
local push_anim = Instance.new("Animation")
push_anim.AnimationId = "rbxassetid://14450776638"
local pushui = game:GetService("Players"):GetPlayerFromCharacter(chr).PlayerGui:WaitForChild("cooldown").group
local bar = pushui:WaitForChild("background"):WaitForChild("bar")
uis.InputBegan:Connect(function(input)
local inputType = input.UserInputType
local keycode = input.KeyCode
if inputType == Enum.UserInputType.Keyboard and keycode == Enum.KeyCode.F then
if debounce == false then
debounce = true
local pushed = false
local push_animTrack = animator:LoadAnimation(push_anim)
push_animTrack:Play()
local R_connect
R_connect = chr:FindFirstChild("Right Arm").Touched:Connect(function(touched_part)
if touched_part.Name == "Torso" then
print(touched_part.Name)
if touched_part.Parent ~= chr then
print(touched_part.Parent.Name)
print("got a possible player")
pushed = true
request_push:FireServer(touched_part.Parent)
end
end
end)
ts:Create(pushui,TweenInfo.new(0.3),{GroupTransparency = 0}):Play()
ts:Create(bar,TweenInfo.new(0.15),{Size = UDim2.new(0, 0,0, 15)}):Play()
push_animTrack.Stopped:Wait()
R_connect:Disconnect()
ts:Create(bar,TweenInfo.new(countdown),{Size = UDim2.new(0, 206,0, 15)}):Play()
wait(countdown)
debounce = false
coroutine.wrap(function()
wait(2)
if debounce == false then
ts:Create(pushui,TweenInfo.new(0.3),{GroupTransparency = 1}):Play()
end
end)()
end
end
end)
Script
local rag_module = require(game:GetService("ServerStorage").ragdoll_module)
local request_push = game:GetService("ReplicatedStorage"):WaitForChild("ragdoll_request")
local ts = game:GetService("TweenService")
local debounce = false
local countdown = 5
local chr = script.Parent
local plr = game:GetService("Players"):GetPlayerFromCharacter(chr)
request_push.OnServerEvent:Connect(function(plr,pushed_char)
if debounce == false then
debounce = true
if pushed_char ~= plr.Character then
rag_module.ragdoll(pushed_char)
end
wait(countdown)
debounce = false
end
end)
Main Module Script
function ragdoll_handler.ragdoll(chr)
local function ragdoll_debris()
for _, ragdoll_debris in pairs(chr:GetDescendants()) do
if ragdoll_debris:IsA("BallSocketConstraint") then
ragdoll_debris.Attachment0:Destroy()
ragdoll_debris.Attachment1:Destroy()
ragdoll_debris:Destroy()
end
end
end
local plr = game:GetService("Players"):GetPlayerFromCharacter(chr)
local head = chr:FindFirstChild("Head")
local torso = chr:FindFirstChild("Torso")
local leftarm = chr:FindFirstChild("Left Arm")
local rightarm = chr:FindFirstChild("Right Arm")
local leftleg = chr:FindFirstChild("Left Leg")
local rightleg = chr:FindFirstChild("Right Leg")
local hum = chr:FindFirstChild("Humanoid")
if hum:GetState() ~= Enum.HumanoidStateType.Ragdoll and hum:GetState() ~= Enum.HumanoidStateType.GettingUp then
ragdollstate_event:FireClient(plr, hum, "ragdoll")
print("fake ragdolling player")
print("ragdolling player")
if hum:GetState() ~= Enum.HumanoidStateType.Ragdoll then
createattachtments(head, torso, leftarm, rightarm, leftleg, rightleg)
motor6d(torso)
print("adding essentials")
end
for _, possibletool in pairs(chr:GetChildren()) do
if possibletool:IsA("Tool") then
possibletool.Parent = plr.Backpack
end
end
torso.Parent:FindFirstChild("HumanoidRootPart").CanCollide = false
game:GetService("RunService").Heartbeat:Wait()
torso.Parent.HumanoidRootPart.Velocity = torso.Parent.HumanoidRootPart.CFrame.LookVector * 25
wait(4.5)
motor6d(torso)
ragdoll_debris()
ragdollstate_event:FireClient(plr, hum, nil)
end
end
I have tried everything to my knowledge and I have no idea why this is even happening. The only thing that prints twice is the Module Script