I'm making a ragdoll script and when the player's health gets low it works fine but when the game is returning the item you get double the weapons. This is a local script under StarterCharacterScripts:
local char = script.Parent
local hum = char.Humanoid
local ragDolled = false
hum.HealthChanged:Connect(function()
if hum.Health <= 25 and ragDolled == false then
ragDolled = true
hum.WalkSpeed = 0
hum.JumpPower = 0
local setEnabled = hum:GetState() ~= Enum.HumanoidStateType.Physics
hum:ChangeState(setEnabled and Enum.HumanoidStateType.Physics or Enum.HumanoidStateType.GettingUp)
char.Animate.Disabled = setEnabled
game.Players.LocalPlayer.Character.HumanoidRootPart.CFrame = game.Players.LocalPlayer.Character.HumanoidRootPart.CFrame * CFrame.Angles(math.rad(90),0,0)
hum:UnequipTools()
local tools = game.Players.LocalPlayer.Backpack:GetChildren()
for i, v in pairs(tools) do
v.Parent = game.ReplicatedStorage.Tools
if setEnabled then
for _,v in pairs(hum:GetPlayingAnimationTracks()) do
v:Stop(0)
end
end
end
end
if hum.Health >= 35 and ragDolled == true then
ragDolled = false
hum.WalkSpeed = 16
hum.JumpPower = 28
local tools = game.ReplicatedStorage.Tools:GetChildren()
for i, v in pairs(tools) do
v.Parent = game.Players.LocalPlayer.Backpack
hum:ChangeState(Enum.HumanoidStateType.GettingUp)
char.Animate.Disabled = false
end
end
end)
Also the guns only dupe in game not in studio.
