Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 2 years ago

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

Log in to vote
0
Answered by 2 years ago

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.

0
Thank you so much man! Sticky_Kermo 2 — 2y
Ad
Log in to vote
0
Answered by 2 years ago

You can use Instance.new() and Humanoid.Died. These links may be useful:

DevHub: Instance

DevHub: Humanoid

Log in to vote
0
Answered by 2 years ago

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.

Answer this question