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

Help with a brick that follows you?

Asked by
FiredDusk 1466 Moderation Voter
8 years ago

This script makes a part follow you. This script works fine but I want the part to be 10 studs above the chars head or torso. This script is in a part btw.

function onPlayerEntered(player)

player.CharacterAdded:connect(function(char)
while wait() do
    script.Parent.CFrame = CFrame.new(char.Torso.Position)
end
end)
end

game.Players.PlayerAdded:connect(onPlayerEntered)

1 answer

Log in to vote
1
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
8 years ago

What You Need To Do

In order for the part to be 10 studs above the character then you need to specify the point of origin, and the offset from that origin. Then set the part's CFrame to the origin's position, multiplied by the offset. In this case, the origin would be your character's Torso, and the offset would be CFrame.new(0,10,0).


Code

function onPlayerEntered(player)
    player.CharacterAdded:connect(function(char)
        while wait() do
            local origin = char:WaitForChild("Torso").CFrame
            local offset = CFrame.new(0,10,0)
            script.Parent.CFrame = origin * offset
        end
    end)
end

game.Players.PlayerAdded:connect(onPlayerEntered)
Ad

Answer this question