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

Why does this script not work?

local Players = game:GetService("Players")
function OnPlayerAdded(player)
	print(player.Name .. " has entered the game")
	repeat wait() until player.Character
	
	local Humanoid = player.Character:findFirstChild("Humanoid")
	if Humanoid then
		local torso = Humanoid.Parent.Torso
		game.Workspace:WaitForChild("Party1")
		-- // Part
local Party1 = Instance.new("Part")
		Party1.FormFactor = "Custom"
		Party1.Size = Vector3.new(1,1,1)
		Party1.CFrame = torso.CFrame * CFrame.new(0,0,0)
		print("The part was created... waiting for the weld")
		Party1.Anchored = false
		-- // Welding
	local Weld = Instance.new("Weld")
		Weld.Part0 = torso
		Weld.C0 = torso.CFrame:inverse()
		
		Weld.Part1 = Party1
		Weld.C1 = Party1.CFrame:inverse()
		Weld.Parent = game.Workspace.Party1	
			
	--// Welding
-- // Part


end

	end

Players.PlayerAdded:connect(OnPlayerAdded)


Pretty much tried everything to solve it, but appareantly im too blind to find a fix, as there is no errors in the input, I just want to make a 1,1,1 sized block be in the middle of the torso (inside of it)

3 answers

✓ Accepted answer

The first red flag I noticed is this line (9):

game.Workspace:WaitForChild("Party1")

This will halt the script until an instance named "Party1" is created in the workspace. From what you've told us, that will never happen, and so the script stops indefinitely.

Also, you would be better off using the CharacterAdded event for something like this, or the code will not run after respawning:

local Players = game:GetService("Players")
function OnPlayerAdded(player)
    print(player.Name .. " has entered the game")
    player.CharacterAdded:connect(function(model)
    local Humanoid = model:FindFirstChild("Humanoid")
    if Humanoid then
        local torso = Humanoid.Parent.Torso
	-- I removed the line here.
        -- // Part
local Party1 = Instance.new("Part")
        Party1.FormFactor = "Custom"
        Party1.Size = Vector3.new(1,1,1)
        Party1.CFrame = torso.CFrame
        Party1.Anchored = false
	-- I'm assuming this is what you intend.
	Party1.Parent = model 
	Party1.Name = "Party1" 
        -- // Welding
    local Weld = Instance.new("Weld")
        Weld.Part0 = torso
        Weld.C0 = torso.CFrame:inverse()
        Weld.Part1 = Party1
        Weld.C1 = Party1.CFrame:inverse()
        Weld.Parent = Party1 
	end)
    --// Welding
-- // Part


end

    end

Players.PlayerAdded:connect(OnPlayerAdded)

Unfortunately, I haven't had time to test this so it may have a few errors. I also added a few things to match how I think you intended this to work.

You never named Party1 part or gave it a parent. You also have it wait for the Party1 part before you make it. Your script is never going to get past line 9.

It had alot of errors, but still it doesn't show a mini-block inside the torso of the character when he joins the game.

The fixed code is this one:

local Players = game:GetService("Players")
function OnPlayerAdded(player)
    print(player.Name .. " has entered the game")
    player.CharacterAdded:connect(function(model)
    local Humanoid = model:FindFirstChild("Humanoid")
    if Humanoid then
        local torso = Humanoid.Parent.Torso
        -- // Part
local Party1 = Instance.new("Part")
        Party1.FormFactor = "Custom"
        Party1.Size = Vector3.new(1,1,1)
        Party1.CFrame = torso.CFrame * CFrame.new(0,0,0)
        Party1.Anchored = false
    Party1.Parent = model 
    Party1.Name = "Party1" 
        -- // Welding
    local Weld = Instance.new("Weld")
        Weld.Part0 = torso
        Weld.C0 = torso.CFrame:inverse()
        Weld.Part1 = Party1
        Weld.C1 = Party1.CFrame:inverse()
        Weld.Parent = Party1 
    end
    --// Welding
-- // Part


end)

Players.PlayerAdded:connect(OnPlayerAdded)

end

Any help on making it work, because i don't really know what im mistaking ... it has the "CharacterAdded" that ~IDidMakeThat added, but it still doesn't really spawn the part inside the torso of the character...

3 comments

0

Don't really know in what im mistaking. It might be some little detail that's not added that makes the block not spawn inside the torso of the character.

0

It really doesn't work even trying to wait for the "Humanoid" child to load, or either the character... any help?

0

Found a fix to it! by myself ;)!

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