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

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

Asked by 5 years ago
Edited 5 years ago
01game.Players.PlayerAdded:Connect(function(player)
02    local cPart = Instance.new("Part")
03        cPart.Name = "cPart"
04        cPart.Size = Vector3.new(5, 3, 0.2)
05        cPart.Shape = Enum.PartType.Cylinder   
06        cPart.Transparency = 1
07        cPart.CanCollide = false
08 
09        cPart.Anchored = true
10 
11        player.CharacterAdded:Connect(function(char)
12            cPart.Parent = char
13            cPart.Position = char.HumanoidRootPart.Position - Vector3.new(0, 4, 0)
14 
15            local function weldBetween(a,b)
View all 26 lines...

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

Log in to vote
0
Answered by 5 years ago

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

01game.Players.PlayerAdded:Connect(function(player)
02    local cPart = Instance.new("Part")
03        cPart.Name = "cPart"
04        cPart.Size = Vector3.new(5, 3, 0.2)
05        cPart.Shape = Enum.PartType.Cylinder   
06        cPart.Transparency = 1
07        cPart.CanCollide = false
08 
09        cPart.Anchored = true
10 
11        player.CharacterAdded:Connect(function(char)
12            cPart.Parent = char.Character
13            cPart.Position = char.Character.HumanoidRootPart.Position - Vector3.new(0, 4, 0)
14 
15            local function weldBetween(a,b)
View all 26 lines...

and where is your first

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

ending

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. GuruNin 5 — 5y
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. GuruNin 5 — 5y
Ad

Answer this question