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

Why when the Player dies, the brick/part does not appear?

So, i want to make that if the Player dies, it should appear a part on the Player torso (to simulate a non-realistic blood), but for some reason i get this on the output: 18:43:59.316 - Workspace.Script:6: bad argument #2 to '?' (string expected, got Object) 18:43:59.317 - Stack Begin 18:43:59.317 - Script 'Workspace.Script', Line 6 18:43:59.317 - Stack End

Script:

game:GetService("Players").PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		character:WaitForChild("Humanoid").Died:Connect(function()
			local a = Instance.new("Part")
			a.BrickColor = BrickColor.new("Really red")
			a.Parent = game.Workspace[character]
		end)
	end)
end)

It would be cool if someone can fix the script since i don't have any idea of how to fix this.

1 answer

✓ Accepted answer

You basically set a's Parent to what you were wanting to be game.Workspace.Character even though you already have the Character itself so there is no reason for doing so. Should be,

game:GetService("Players").PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(character)
        character:WaitForChild("Humanoid").Died:Connect(function()
            local a = Instance.new("Part")
            a.BrickColor = BrickColor.new("Really red")
            a.Parent = character
        end)
    end)
end)

4 comments

0

Thank you! it worked

0

Should "a.Parent = character" be "a.Parent = character.Torso" ?

0

I tried the two things and it looks like the same.

0

a's Parent being the Part can be basically anything you want. Anywhere in the Worksapce will work. 

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