Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

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

1 comment

0

i inserted the script you sent and the parts spawn directly in the center of the map. why

This discussion is preserved as it was. New answers, comments, and votes are closed.