My game was working fine until sometime ago where I think the bug is that the server script inside StarterCharacterScripts isn’t functioning when player dies/resets/ Means it only functions once when he joins.
Could we see the script if possible?
Sure.
local PS = game:GetService("PhysicsService")
local c = script.Parent
local Hum = c.Humanoid
Hum.BreakJointsOnDeath = false
local M = require(game.ReplicatedStorage.Module)
for _,C in pairs(c:GetDescendants()) do
if C:IsA("Motor6D")then
local socket = Instance.new("BallSocketConstraint",C.Parent)
local a0,a1 = Instance.new("Attachment"),Instance.new("Attachment")
a0.Parent,a1.Parent = C.Part0,C.Part1
socket.Attachment0,socket.Attachment1 = a0,a1
a0.CFrame,a1.CFrame = C.c0,C.c1
socket.LimitsEnabled = true
socket.TwistLimitsEnabled = true
socket.Enabled = false
elseif C:IsA'BasePart' then
PS:SetPartCollisionGroup(C,"C")
if C.Name == "HumanoidRootPart" then
PS:SetPartCollisionGroup(C,"HRP")
end
end
end
Hum.Died:Connect(function()
M.Ragdoll(c)
end)
game.ReplicatedStorage.RemoteEvent.Ragdoll.OnServerEvent:Connect(function(plr)
local char = plr.Character or plr.CharacterAdded:Wait()
M.Ragdoll(char)
end)
local u = c.UpperTorso
for _,v in pairs(game.ReplicatedStorage.Dummy.UpperTorso:GetChildren()) do
if v.Name == "Trail" or v.Name == "T0" or v.Name == "T1" then
v:Clone().Parent = u
end
end
u.Trail.Attachment0 = u.T0
u.Trail.Attachment1 = u.T1
Add a :WaitForChild() on the humanoid and possibly the head.
I just found out that it takes a lot of time to respawn. Respawn time is 2 seconds in players property and characterautoloads is true.
I’m a little confused as to what you mean.
Ok, I have two humanoid died events. One in starter scripts as u can see above and another in server script inside Server SCript Service.
Ah okay, and you’re sure it’s in StarterCharacterScripts, not StarterPlayer or StarterPlayerScripts?
Yep! I am. I also tried printing inside Died event and it doesnt print when I reset.
Try changing
local Hum = c.Humanoid
to
local Hum = c:WaitForChild('Humanoid')
one more thing, same code worked fine before. I used two died events and they worked fine earlier. Plus, I didn’t have to wait for Humanoid earlier. Doesn’t make any difference when I tried with waitforchild…
Alright, thanks for the info.
Any errors?
If not, possibly add
repeat wait() until #c:GetDescendants() > 15 --[[replace with 6 if your game is R6]]
or
repeat wait() until c:FindFirstChild('Head') and c:FindFirstChild('Humanoid')
See if that makes any difference.
If none of these work, I think you should consider handling all of your deaths from the server in a single script inside of ServerScriptService.
I printed inside the r15 loop and it prints 15 times. Everything works on first time when character loads but not when he dies/resets. Tried printing humanoid without using waitforchilds/findfirstchild and it prints Humanoid.
Basically, Humanoid.Died event isn’t working.
Fixed by checking for Health becoming 0, Died event doesn’t fire even if Humanoid’s health is 0.
local HumanoidDiedConnection = "Temp"
local HumanoidDiedResponse = function()
if not(Humanoid) or Humanoid.Health == 0 then
HumanoidDiedConnection:Disconnect()
print("Died")
end
end
HumanoidDiedConnection = Humanoid:GetPropertyChangedSignal("Health"):Connect(HumanoidDiedResponse)