since my previous topic was closed for whatever reason, making a new one.
Basically, im trying to do client sided kill effects using NetworkOwnership. ( server kill effects are way too laggy.) When ragdolling, all the constraints are built correctly but the physics does not apply unless touched by another player.
Code and vide.
local event = script.Parent
local PlayerData = require(script.Parent.Parent.Parent.PlayerData.PlayerData)
local CommonServerFunctions = require(script.Parent.Parent.Parent.CommonServerFunctions)
local ServerData = require(script.Parent.Parent.Parent.ServerData)
local RagdollModule = require(game.ServerScriptService.General.DefaultRagdoll)
local DefaultKillEffect = require(game.ServerStorage.Content.Knives.StockKnife.KillEffect)
local function setRagdollOwnership(character)
if character then
for _, part in pairs(character:GetDescendants()) do
if part:IsA("BasePart") then
part:SetNetworkOwner(nil)
end
end
end
end
event.Event:Connect(function(characterModel, knifeData, colorData, hitData)
if knifeData.WasFused then
knifeData.RealName = knifeData.Fused.ActualFuse
end
local selectedKillEffect
local killEffectName
local attacker = game.Players[characterModel.Name]
local context = {
player = attacker,
KEffectFunctions = require(game.ServerScriptService.General.KEffectFunctions),
HitData = hitData,
ragdoll = RagdollModule
}
context.HitData.HitVelocity = CFrame.new(context.HitData.HitVelocity):Inverse().p
for _, item in pairs(game.ServerStorage.Content:GetDescendants()) do
if item.Name == knifeData.RealName then
local killEffectFunc = require(item.KillEffect)
if type(killEffectFunc) == "function" then
killEffectName = knifeData.RealName
selectedKillEffect = killEffectFunc
end
local gamepasses = PlayerData.ReadPlayerData(hitData.Attacker.UserId, { "Inventory", "Gamepasses" })
for _, pass in pairs(gamepasses) do
if pass.RealName == "KillEffectTransfer" then
local equippedKnife = PlayerData.ReadPlayerData(hitData.Attacker.UserId, { "EquippedItems", "Knives", 1 })
if equippedKnife.WasFused then
equippedKnife = { RealName = equippedKnife.Fused.ActualFuse }
end
for _, knife in pairs(game.ServerStorage.Content.Knives:GetChildren()) do
if knife.Name == equippedKnife.RealName then
local altKillEffect = require(knife.KillEffect)
if type(altKillEffect) == "function" then
killEffectName = equippedKnife.RealName
selectedKillEffect = altKillEffect
end
break
end
end
break
end
end
end
end
characterModel.Archivable = true
local clonedCharacter = characterModel:Clone()
characterModel:Destroy()
characterModel = clonedCharacter
characterModel.Parent = workspace
characterModel.HumanoidRootPart.CFrame = CFrame.new(context.HitData.HitPosition)
print(hitData)
setRagdollOwnership(characterModel)
game.ReplicatedStorage.GameEvents.KillEffect:FireAllClients(characterModel, context, killEffectName)
script.Parent.Parent.PlayerDied:Fire(characterModel.Name)
if selectedKillEffect then
-- selectedKillEffect(characterModel, CommonServerFunctions, context, context.HitData)
else
-- DefaultKillEffect(characterModel, CommonServerFunctions, context, context.HitData)
end
end)