Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to make script insert a stringvalue into player after death?

Script should insert a stringvalue into players torso after player dies. I've coded a ragdoll which will make body stay for a while and i need a ragdoll to have stringvalue inside it

3 answers

✓ Accepted answer

This can be easily achieved by humanoid.Died or humanoid.HealthChanged. Here is the examples:

Humanoid.Died:Connect(function()
	local StringValue = Instance.new("StringValue", game.Players.LocalPlayer)
end)

Remember that these can only work on a local script! (Both examples use Instance.new, don't forget that too)

Humanoid.HealthChanged:Connect(function(health)
if health == 0 then 
	local StringValue = Instance.new("StringValue", game.Players.LocalPlayer)
end
end)

That is basically it

Extra (On server)

local plrs = game.Players

plrs.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		local Humanoid = character:WaitForChild("Humanoid")
		if player and humanoid then
			Humanoid.Died:Connect(function()
				local StringValue = Instance.new("StringValue", player)
			end)
		end
	end)
end)

That is basically it! Thanks for reading this even if you did, hope this helps on putting a value in a player when they die.

1 comment

0

Thank you so much man!

in startercharacterscripts:

script.Parent.Humanoid.Died:Connect(function()
game.ReplicatedStorage.stringValue:Clone().Parent = script.Parent
end)

put the string value that needs to cloned into rep storage then when they die this will clone it in.

This discussion is preserved as it was. New answers, comments, and votes are closed.