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

Script won't teleport part to it's proper position?

game.Players.PlayerAdded:Connect(function(player)
	local cPart = Instance.new("Part")
		cPart.Name = "cPart"
		cPart.Size = Vector3.new(5, 3, 0.2)
		cPart.Shape = Enum.PartType.Cylinder	
		cPart.Transparency = 1
		cPart.CanCollide = false
		
		cPart.Anchored = true
		
		player.CharacterAdded:Connect(function(char)
			cPart.Parent = char
			cPart.Position = char.HumanoidRootPart.Position - Vector3.new(0, 4, 0)

			local function weldBetween(a,b)
				local weld = Instance.new("ManualWeld", a)
				weld.Part0 = a
				weld.Part1 = b
				weld.C0 = a.CFrame:inverse() * b.CFrame
				return weld
			end

			local weld = weldBetween(char.HumanoidRootPart, cPart)
			
			cPart.Position = tileGrid:FindFirstChild("PlayerStart"..playerInt.Value).Position + Vector3.new(0,3,0)
		end)

So here I have a script which creates a "cPart" (Control Part) and welds it to the player's character for easy manipulation of the player's character. It starts by putting the cPart in the same position as the player's character, then welds the character and the part together, then it is supposed to teleport the cPart to the proper starting point. Problem is, this last step just doesn't work at all. In the game the characters are stuck floating where they spawned, welded to the cPart. How can I get the server to put the cParts in the correct position so everybody can see it? Thanks

EDIT: I included a print(cPart.Position) at the end of this script just to see what it would say, and the output says that the cPart's position is the same as the position of the "PlayerStart" part that I am attempting to teleport to, indicating that it teleported correctly. But in the game world, this clearly isn't true, it's just how I described above. This is extremely bizarre to me. Help?

1 answer

if you want the same pos as HumanoidRootPart you have to call the Character first like

game.Players.PlayerAdded:Connect(function(player)
    local cPart = Instance.new("Part")
        cPart.Name = "cPart"
        cPart.Size = Vector3.new(5, 3, 0.2)
        cPart.Shape = Enum.PartType.Cylinder    
        cPart.Transparency = 1
        cPart.CanCollide = false

        cPart.Anchored = true

        player.CharacterAdded:Connect(function(char)
            cPart.Parent = char.Character
            cPart.Position = char.Character.HumanoidRootPart.Position - Vector3.new(0, 4, 0)

            local function weldBetween(a,b)
                local weld = Instance.new("ManualWeld", a)
                weld.Part0 = a
                weld.Part1 = b
                weld.C0 = a.CFrame:inverse() * b.CFrame
                return weld
            end

            local weld = weldBetween(char.HumanoidRootPart, cPart)

            cPart.Position = tileGrid:FindFirstChild("PlayerStart"..playerInt.Value).Position + Vector3.new(0,3,0)
        end)

and where is your first

game.Players.PlayerAdded:Connect(function(player)

ending

2 comments

0

Changing char to char.Character just introduced errors where there weren't any before. The ending to the initial game.Players.PlayerAdded comes later after some more code that isn't relevant to the question.

0

Anyhow that's not the problem I'm trying to solve. The cPart teleports and welds to the player just fine, it's moving it again to the proper position that's giving me issue.

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