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

how to make a part spawn where the player is looking?

Asked by 1 year ago

i have this script that lets me spawn balls on E

Tear = game.ReplicatedStorage.tear
local plr = game.Players.LocalPlayer

UserInput = game:GetService("UserInputService")

UserInput.InputBegan:Connect(function(input , gameProccesedevent)
    if input.KeyCode == Enum.KeyCode.E then
        local tearclone = Tear:Clone()
        tearclone.Parent = game.Workspace
        tearclone.CFrame = plr.Character.HumanoidRootPart.CFrame + plr.Character.HumanoidRootPart.CFrame.lookVector * 5
    end

end)

right now, the ball spawns infront of the humanoidrootpart. but i want it to spawn 5 studs away from where the player is looking. im pretty bad at inserting stuff to scripts, so a modified version of this script would be great.

1 answer

Log in to vote
0
Answered by
pwx 1581 Moderation Voter
1 year ago

If you have a rotating head, you can use the Head at a CFrame point, otherwise you can use the CurrentCamera.

tearclone.CFrame = plr.Character.HumanoidRootPart.CFrame + plr.Character.Head.CFrame.lookVector * 5

or

tearclone.CFrame = plr.Character.HumanoidRootPart.CFrame + workspace.CurrentCamera.CFrame
0
i inserted the script you sent and the parts spawn directly in the center of the map. why pakancina 19 — 1y
Ad

Answer this question