Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why won't the weld always be created in front of the player ?

Asked by 5 years ago
Edited 5 years ago

I've made a script that create a circle in front of the player that follows him (it stays in front of him). However, when the player turns around, the circle isnt in front of the player anymore, it's always pointing in the same direction

Here is the script :

game.ReplicatedStorage.RemoteEvent.OnServerEvent:connect(function(player)
    local circle = Instance.new("Part", game.Workspace) -- I didnt change the size of the part, so basically, it's not a circle (but with some decals it will become one)
    local weld = Instance.new("ManualWeld", circle)

    circle.Size = Vector3.new(1.5,1.5,0.01)
    circle.Anchored = false
    circle.CanCollide = false
    circle.Transparency = 1
    weld.Part0 = circle
    weld.Part1 = player.Character.HumanoidRootPart
    weld.C0 = circle.CFrame
    weld.C1 = player.Character.HumanoidRootPart.CFrame * CFrame.new(1.35,1.25,-2.75)
end)

1 answer

Log in to vote
3
Answered by
Ziffixture 6913 Moderation Voter Community Moderator
5 years ago
Edited 5 years ago

This is because you’re forgetting a very crucial piece of the formula whilst welding. The CFrame was set, meaning the object will stay in the place it was asked to. There is a method used tie the CFrame of an object to mimic the other, in this case, the lookVector of the Character.

This can easily be fixed by writing

Weld.C0 = circle.CFrame:Inverse()
Weld.C1 = HumanoidRootPart.CFrame:Inverse() * CFrame.new()

I do suggest you set the CFrame of the circle to be ahead of the Character before setting the Objects CFrame, I could break

Hope this fixes your issue

0
good job teaching people about inverse +1 Imperialy 149 — 5y
0
Oh, thanks;) I’ll return the favour Ziffixture 6913 — 5y
Ad

Answer this question