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

Making a morph script, but the part rotates differently everytime I trigger the script?

Asked by 4 months ago
Edited 4 months ago

I'm trying to make a brick part of the character appearance, but it rotates differently everytime I trigger the script. How do I get it to not rotate differently everytime I trigger the touch event?

script.Parent.Touched:Connect(function(hit)
    local newPart = game.ServerStorage.Hazmat.HazmatMask:Clone()
    if hit.Parent:FindFirstChild("Humanoid") then
        if hit.Parent:FindFirstChild("HazmatMask") then
    else
        newPart.Parent = hit.Parent
        newPart.CFrame = CFrame.new(hit.Parent:FindFirstChild("Head").Position) 
        local weld = Instance.new("ManualWeld")
        weld.Part0 = newPart
        weld.Part1 = hit.Parent:FindFirstChild("Head")
        weld.C0 = newPart.CFrame:inverse() * hit.Parent:FindFirstChild("Head").CFrame
        weld.Parent = hit.Parent:FindFirstChild("Head")
end
    end
end)


1 answer

Log in to vote
1
Answered by
sleazel 394 Moderation Voter
4 months ago
Edited 4 months ago

Replace:

newPart.CFrame = CFrame.new(hit.Parent:FindFirstChild("Head").Position)

with:

newPart.CFrame = hit.Parent:FindFirstChild("Head").CFrame

If your part in ScriptStorage is not positioned properly, you may still the get it wrong, but it will be wrong always the same. Consider this code, replacing x,y,z and r with proper values or repositon CFramePrimaryPart in ServerStorage.

newPart.CFrame = (hit.Parent:FindFirstChild("Head").CFrame  + Vector3.new(x,y,z)) * CFrame.Angles(0,math.rad(r),0)

Also consider adding debounce, to avoid having a multiple masks on one character.

0
It doesn't rotate anymore, but it positions itself differently now. Depanding on where I touch the part. Gameplay28 69 — 4mo
0
I have checked the code with random mask from library, it works. Weird. Maybe your HazmatMask model is bad. sleazel 394 — 4mo
0
It doesn't do this till I add to the Vector3 value. Gameplay28 69 — 4mo
0
I may be overcomplicating things. Is your HazmatMask made of a single part with mesh? sleazel 394 — 4mo
View all comments (6 more)
0
No, It's a union, could that be the reason it's not working? Gameplay28 69 — 4mo
0
Alright, I tested it with a normal part and it works. So I guess it is because of it being a union. Gameplay28 69 — 4mo
0
Is there a way it could work with a union? Gameplay28 69 — 4mo
0
Sorry, i don't know. I am not really using the unions. Try creating invisible, non collidable block in the middle and weld the union to it. Then make a union as a child of this part, and CFrame only this part. sleazel 394 — 4mo
0
Smart thinking, I'll try it. Gameplay28 69 — 4mo
0
Thanks a lot with helping, I did what you did but with a head. So I wouldn't have to change the vector value. Gameplay28 69 — 4mo
Ad

Answer this question