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

is there a way to do a playeradded weld script ?

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

2 comments

0

Which line doesn't work?

0

line 5 and7

2 answers

✓ Accepted answer

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.

5 comments

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

0

17:28:32.374 - Infinite yield possible on 'Players.Player1:WaitForChild("Character")' - the problem

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)

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.

0

now the problem is inverse is not a valid member of UnionOperation at line 12

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

1 comment

0

dind't work error said Workspace.Script:4: attempt to index field 'Character' (a nil value)

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