Still have questions? Join our Discord server and get real time help.
Log in to vote

Orientation of object is wrong only first time I call function. How can I fix that?

Asked by 1 month ago

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

local items = {}

    function items.get(player, item)
        local successful = false
        local object, pos, ang
        local animation ="Animation")

        if player.PlayerData.Item.Value == nil then
            --Get item type
            if item == "Soda" then
                object = game:GetService("ServerStorage").Soda
                animation.AnimationId = ""
                pos =,-1.3,0)
                ang =,0,-90)

            local arm = player.Character["Right Arm"] --Spawning and position
            local clone = object:Clone()
            clone.Anchored = false
            clone.Parent = arm
            player.PlayerData.Item.Value = clone

            clone.CFrame = arm.CFrame:ToWorldSpace(pos)
            clone.Orientation = ang

            local weld ="WeldConstraint") --Weld parts
            weld.Parent = clone
            weld.Part0 = arm
            weld.Part1 = clone

            local animationTrack = player.Character.Humanoid:LoadAnimation(animation)

            successful = true

        return successful

return items

2 answers

Log in to vote
Answered by 1 month ago

If you want to get past the problem of it not working first time what you want to do is call the function first, delete the soda, then call the function again and hopefully the soda should be in the correct place.

That doesn't fix the problem. You're suggesting to ignore it ThreeTwigs 0 — 1mo
No offence by the way ThreeTwigs 0 — 1mo
Log in to vote
Answered by 1 month ago

So I think I figured it out. I swapped right arm for torso and adjusted the position and rotation and it worked. Thanks @Gooncreeper for contribution

Answer this question