I have a script that clones 3 rings and places it at the player. What happens is the rings always spawn at a certain angle, and not toward the player. How can I make this so the clones always spawn in front of the player?
Script:
game.ReplicatedStorage.Remotes.Uppercut.OnServerEvent:Connect(function(plr)
local character = plr.Character
local humanoidrootpart = character.HumanoidRootPart
local shockwave = game.ReplicatedStorage.Moves.EpicPunch.FirstRing:Clone()
shockwave.Parent = workspace.Fx
shockwave.Position = Vector3.new(humanoidrootpart.Position.X, humanoidrootpart.Position.Y, humanoidrootpart.Position.Z + 3)
local shockwave1 = game.ReplicatedStorage.Moves.EpicPunch.SecondRing:Clone()
shockwave1.Parent = workspace.Fx
shockwave1.Position = Vector3.new(humanoidrootpart.Position.X, humanoidrootpart.Position.Y, humanoidrootpart.Position.Z + 5)
local shockwave2 = game.ReplicatedStorage.Moves.EpicPunch.ThirdRing:Clone()
shockwave2.Parent = workspace.Fx
shockwave2.Position = Vector3.new(humanoidrootpart.Position.X, humanoidrootpart.Position.Y, humanoidrootpart.Position.Z + 7)
end)
--//Services
local ReplicatedStorage = game:GetService("ReplicatedStorage")
--//Functions
ReplicatedStorage.Remotes.Uppercut.OnServerEvent:Connect(function(player)
local character = player.Character
local humanoidRootPart = character and character:FindFirstChild("HumanoidRootPart")
if not humanoidRootPart then
return
end
local shockwave = ReplicatedStorage.Moves.EpicPunch.FirstRing:Clone()
shockwave:PivotTo(humanoidRootPart.CFrame + humanoidRootPart.CFrame.LookVector * 3)
shockwave.Parent = workspace.Fx
local shockwave1 = ReplicatedStorage.Moves.EpicPunch.SecondRing:Clone()
shockwave1:PivotTo(humanoidRootPart.CFrame + humanoidRootPart.CFrame.LookVector * 5)
shockwave1.Parent = workspace.Fx
local shockwave2 = ReplicatedStorage.Moves.EpicPunch.ThirdRing:Clone()
shockwave2:PivotTo(humanoidRootPart.CFrame + humanoidRootPart.CFrame.LookVector * 7)
shockwave2.Parent = workspace.Fx
end)
You could use CFrames in this case to get it facing in front of you whenever triggering the remote.
game.ReplicatedStorage.Remotes.Uppercut.OnServerEvent:Connect(function(plr)
local character = plr.Character
local HMR = character.HumanoidRootPart
local shockwave = game.ReplicatedStorage.Moves.EpicPunch.FirstRing:Clone()
shockwave.Parent = workspace.Fx
shockwave.CFrame = HMR.CFrame * CFrame.new(0,0,-3) * CFrame.Angles(math.rad(-90),0,0)
local shockwave1 = game.ReplicatedStorage.Moves.EpicPunch.FirstRing:Clone()
shockwave1.Parent = workspace.Fx
shockwave1.CFrame = HMR.CFrame * CFrame.new(0,0,-5) * CFrame.Angles(math.rad(-90),0,0)
local shockwave2 = game.ReplicatedStorage.Moves.EpicPunch.FirstRing:Clone()
shockwave2.Parent = workspace.Fx
shockwave2.CFrame = HMR.CFrame * CFrame.new(0,0,-7) * CFrame.Angles(math.rad(-90),0,0)
end)
Assuming it’s flat at CFrame.Angles(0,0,0), setting it to CFrame.Angles(math.rad(-90),0,0) would make the front surface face forwards. If not, feel free to experiment with the values until you get your desired orientation.