Hi, as per title I want to attach an object to every player character server side. I followed this tutorial “https://www.youtube.com/watch?v=ftArvcVG26U&t” but for some reasons it doesn’t work…
That’s the script:
local players = game:GetService("Players")
local ss = game:GetService("ServerStorage")
local dummyR15 = ss.RigR15
function weld(partA, partB, offsetCFrame)
partA.CFrame = partB.CFrame * offsetCFrame
local weldConstraint = Instance.new('WeldConstraint')
weldConstraint.Parent = partA
weldConstraint.Part0 = partA
weldConstraint.Part1 = partB
end
function onCharacterAdded(character)
local newWeld = dummyR15.Flashlight:Clone()
local weldPart = character.UpperTorso
weld(newWeld, weldPart, newWeld.WeldPart.Value.CFrame:Inverse() * newWeld.CFrame)
newWeld.Parent = character
end
players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(onCharacterAdded)
end)
for i, player in pairs(players:GetPlayers()) do
player.CharacterAdded:Connect(onCharacterAdded)
if (player.Character) then
onCharacterAdded(player.Character)
end
end
I think the problem is here
function weld(partA, partB, offsetCFrame)
partA.CFrame = partB.CFrame * offsetCFrame
local weldConstraint = Instance.new('WeldConstraint')
weldConstraint.Parent = partA
weldConstraint.Part0 = partA
weldConstraint.Part1 = partB
end
as the weldconstraints gets created and it has the right parts in it but it just doesn’t link the 2 parts togheter (A flashlight and the UpperTorso in this specific case).
Any ideas?
I did something similar recently but i made it an accesory tied to player’s front torso, is there any reason as to why you can’t use an accesory (also i think a Weld is better than a WeldContraint for this but not certain)
No reasons. The only thing I care about is that it attaches to the player and I can modify the properties of a spotlight in the mesh. So if you are able to tell me how to do it I can try it and see if it works.
at the start of the script made it work. What I’m thinking at this point is that even if there is the
character:WaitForChild("UpperTorso")
the script gets executed before the UpperTorso gets fully loaded which leads to it not get linked to the flashlight. Thanks to everyone who tried to help me!