My Part isn't appearing in front of the player when Key is pressed

I’m trying to have my part appear in front of the character as soon they press F but its not working. I tried to do Vector3 but I was told CFrame was a better way to do it.

[Local Script]

local UIS = game:GetService("UserInputService")
local RS = game:GetService("ReplicatedStorage")
local Remote = RS.Remotes:WaitForChild("FireSummonEvent")
local debounce = false
local FiresummonPart = RS.Misc:WaitForChild("FS")


---script///

UIS.InputBegan:Connect(function(Input, GP)
   if GP then return end
   if Input.KeyCode == Enum.KeyCode.F and not debounce then
   	print("BOOM")
   	debounce = true
   	Remote:FireServer()
   	wait(5)
   	debounce = false
   end
end)

[Server Script]

local RS = game:GetService("ReplicatedStorage")
local Remote = RS.Remotes:WaitForChild("FireSummonEvent")
local FiresummonPart = RS.Misc:WaitForChild("FS")

Remote.OnServerEvent:Connect(function(Player)
	local Character = Player.Character or Player.CharacterAdded:Wait()
	local HRP = Character:WaitForChild("HumanoidRootPart")
	local FireBall = FiresummonPart:Clone()
FireBall.CFrame = HRP.CFrame *CFrame.new(0,0,10)
	
	
end)

What worked for me was CFrame.lookAt(). So my code was:
humanoidrootpart2.CFrame = CFrame.lookAt(humanoidrootpart1.Position + Vector3.new(0, 0, 3), humanoidrootpart1.Position)

So in this case, yours would be:

Fireball.CFrame = CFrame.lookAt(HRP.Position + Vector3.new(0,0,3), HRP.Position)

I hope this helps!

2 Likes

If that doesn’t work, try:

FireBall.Position = HRP.Position + (HRP.CFrame.LookVector * 10)

and if you need it to look towards the player, then

FireBall.Position = CFrame.lookAt(HRP.Position + (HRP.CFrame.LookVector * 10), HRP.Position)

You need to set the Parent property of the cloned FiresummonPart. You could set this to the workspace or also most any descendant of the workspace

1 Like

You might also want to implement a server sided debounce to prevent exploiters from lagging out your game with parts.

1 Like

This was a huge help! Worked like a charm. All though WartioSvug did solve the appearance problem, your answer is what I was looking for. Lookvector was a better option then CFrame.LookAt

Video:
https://gyazo.com/2feb488fde3d92b438a69448228667a6

Thanks!

2 Likes

Thank you for the suggestion, I will do this ASAP