trying to make system where it leaves player ragdoll body and flings it
made red cube, click on red cube it flings and ragdolls player
if player health is 0 or below it’ll leave the player dead body
however im getting problems with it, every time it kills the player there is noticeable lag
and prints out this message
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerStorage = game:GetService("ServerStorage")
local RagdollModule = require(ServerStorage.RagDoll) --ragdolls player
local flingEvent = ReplicatedStorage.FlingCharacter --flings player
local controlEvent = ReplicatedStorage.ControlsEvent --enable/disable player controls
local ragdollState = ReplicatedStorage.RagdollState --enable/disable ragdoll state
local part = script.Parent
local click = part.ClickDetector
local flingForce: number = 500
local damage: number = 50
click.MouseClick:Connect(function(player)
local char = player.Character
if not char.Humanoid then return end
controlEvent:FireClient(player, false) --disable controls
ragdollState:FireClient(player, true) --enable ragdoll state
RagdollModule.ragdoll(char)
flingEvent:FireClient(player, (char.HumanoidRootPart.Position - part.Position).Unit, flingForce) --fling character on client
char.Humanoid.Health -= damage
if char.Humanoid.Health == 0 then
char.HumanoidRootPart:SetNetworkOwner(player) --not sure what this do
else
task.wait(2)
RagdollModule.unragdoll(player.Character)
ragdollState:FireClient(player, false) --disable ragdoll state
end
controlEvent:FireClient(player, true) --enable controls
end)
probably the main issue happens in the death script,
player ragdolls on death and puts all player body parts into a new model, so it doesn’t despawn
–here’s the death script
local ServerStorage = game:GetService("ServerStorage")
local ragdoll = require(ServerStorage.RagDoll)
local character = script.Parent
local humanoid = character.Humanoid
humanoid.BreakJointsOnDeath = false
humanoid.Died:Connect(function()
ragdoll.ragdoll(character)
local model = Instance.new("Model")
model.Parent = workspace
for _, part in pairs(character:GetChildren()) do
if part.Name == "HumanoidRootPart" then continue end
part.Parent = model
end
end)
–note if thats not enough for you
then here’s the place download flingragdoll.rbxl (53.8 KB)
controlEvent:FireClient(player, true) needs to be fired once the player’s character respawns. Instead, its being fired when the current character is dead.
the control event only disable’s player controls so they cant move while ragdoll
local PlayerModule = require(LocalPlayer.PlayerScripts:WaitForChild("PlayerModule"))
local Controls = PlayerModule:GetControls()
local controlEvent = ReplicatedStorage.ControlsEvent
controlEvent.OnClientEvent:Connect(function(enable)
if enable then
Controls:Enable()
else
Controls:Disable()
end
end)
well when the character dies, if controlEvent:FireClient(player, true) is sent, then it throws that error and causes lag. You need to check if the character is dead, and if it is, then dont send that event
Control needs to stay off until they player’s character is fully respawned
i just disabled the script, and it does not cause lag
im thinking the lag is probably created by one of the core scripts, but i dont have access to it and nor should i change any of its code
A decided to test it after removing line 20 aswell. The player cant move when they’re ragdolled no matter what. So it looks like changing the control state of the player was un-needed
you’re probably right on the controls, i probably don’t need it, i only had it incase because at one point the player walking while ragdoll looked kinda silly