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

is there a way to do a playeradded weld script ?

Asked by 7 years ago
Edited 7 years ago

ive tried multiple times to make something weld above the players head when he spawns into the game but i just cant figure it out

ive got a union saved in the serverstorage and it is supposed to clone with and then the clone gets welded above the players head

one of my several attempts:

function playerAdded(player)
    local clone = game.ServerStorage.Crystal:Clone()
    local player = game.Players.PlayerAdded

    head = player.Humanoid.Head
    clone.CFrame = head.CFrame * CFrame.new(0,3,0)
    weld = Instance.new("Weld")
    weld.Part0 = head
    weld.C0 = head.CFrame:inverse()
    weld.Part1 = clone
    weld.C1 = clone:inverse()
    weld.Parent = clone
end

game.Players.PlayerAdded:connect(playerAdded)

line 5 and 7 are the errors

if there is more information needed feel free to comment

0
Which line doesn't work? TheLuckyZ 24 — 7y
0
line 5 and7 TigerClaws454 48 — 7y

2 answers

Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

TheLuckyZ is right: "You don't need line 3, as player is already defined in the function's parameters. Line 5 should be head player.Character.Head." You will also need to wait for the character to spawn because the character spawns a little AFTER the player is added to the game. This is why your script couldn't find the character. You can use WaitForChild to yield the script until the character is found such as:

character = workspace:WaitForChild(player.Name)
head = character:WaitForChild("Head")

Then work with the head.

0
i still get a infinite yield problem the script now looks like function playerAdded(player) local clone = game.ServerStorage.Crystal:Clone() head = player:WaitForChild("Character"):WaitForChild("Head") clone.CFrame = head.CFrame * CFrame.new(0,3,0) weld = Instance.new("Weld") weld.Part0 = head weld.C0 = head.CFrame:inverse() weld.Part1 = clone weld.C1 = clone:inve TigerClaws454 48 — 7y
0
17:28:32.374 - Infinite yield possible on 'Players.Player1:WaitForChild("Character")' - the problem TigerClaws454 48 — 7y
0
My bad. character = workspace:WaitForChild(player.Name) should yield for the character. I've updates the lines above. You get the infinite yield possible warning because :WaitForChild() could possibly yield the script forever if the item does not spawn. To avoid this you can use a second parameter to end the yield after waiting a set amount of time like workspace:WaitForChild(player.Name, 5) VinnyTheButcher 278 — 7y
0
You can also avoid the yield issue all together by binding "player.CharacterAdded:connect(function() --Do stuff. end)" however this means the part will be welded whenever the player spawns. But, you can use an if statement to check if the character already has the crystal welded. VinnyTheButcher 278 — 7y
0
now the problem is inverse is not a valid member of UnionOperation at line 12 TigerClaws454 48 — 7y
Ad
Log in to vote
1
Answered by 7 years ago

You don't need line 3, as player is already defined in the function's parameters. Line 5 should be head player.Character.Head.

0
dind't work error said Workspace.Script:4: attempt to index field 'Character' (a nil value) TigerClaws454 48 — 7y

Answer this question