Orientation of object is wrong only first time I call function. How can I fix that?
This is code that spaws Soda and attaches it to player. The problem is that first time the function is called it spaws Soda is wrong orientation. Second times it's called it's as intended.
Images for reference:
image1,
image2
03 | function items.get(player, item) |
04 | local successful = false |
05 | local object, pos, ang |
06 | local animation = Instance.new( "Animation" ) |
08 | if player.PlayerData.Item.Value = = nil then |
10 | if item = = "Soda" then |
11 | object = game:GetService( "ServerStorage" ).Soda |
13 | pos = CFrame.new( 0 ,- 1.3 , 0 ) |
14 | ang = Vector 3. new( 0 , 0 ,- 90 ) |
17 | local arm = player.Character [ "Right Arm" ] |
18 | local clone = object:Clone() |
19 | clone.Anchored = false |
21 | player.PlayerData.Item.Value = clone |
23 | clone.CFrame = arm.CFrame:ToWorldSpace(pos) |
24 | clone.Orientation = ang |
26 | local weld = Instance.new( "WeldConstraint" ) |
32 | local animationTrack = player.Character.Humanoid:LoadAnimation(animation) |