function onPlayerAdded(player)
player.CharacterAdded:Connect(onCharacterAdded)
end
function onCharacterAdded(character)
local h = character:WaitForChild("Humanoid")
if h then
local arrow = game.ReplicatedStorage.Arrow:Clone()
local weld = Instance.new("Weld")
arrow.Name = character.Name
arrow.Parent = workspace
weld.Parent = arrow.PrimaryPart
weld.Part0 = arrow.PrimaryPart
weld.Part1 = h.Parent:FindFirstChild("HumanoidRootPart")
weld.C0 = CFrame.new(0, -5, 0)
end
end
game.Players.PlayerAdded:Connect(onPlayerAdded)
while wait() do
for i, v in pairs(workspace:GetChildren()) do
if v.Name == "Arrow" then
v:SetPrimaryPartCFrame(CFrame.new(v.PrimaryPart.Position, workspace.Target.Position))
end
end
end
I’m pretty sure it’s because of the welds, how do I get around this? I welded an arrow to the players character just over their head and when i try to set the primary part cframe of the arrow it doesn’t rotate…
In the onCharacterAdded function you’ve got a line that reads arrow.Name = character.Name. This means that, if the arrow was created for my character for example, the Name of the arrow would be "ThanksRoBama". That means the Name of the arrow is not"Arrow".
In the while loop at the bottom of the script, you’re repeatedly looping through each child in game.Workspace, checking if the Name of that child is "Arrow", and if that’s the case, updating it’s CFrame. But since you changed the Name of the arrow when you created it, there’s almost no way that it can actually have the Name that you expected (that only happens if the player whose name is actually “Arrow” joins the game).
To fix it, you could just choose not to rename the arrow (i.e. remove the line of code that reads arrow.Name = character.Name). But that might break other scripts in your game. Let me know if it does, and I’ll teach you some other ways of referring to objects than by Name, which might be better for your specific case.