Help on left and right vector

this code doesn’t quite seem to be doing what i want it to do

local right = true
local nex = HRP.CFrame.RightVector + HRP.Position
for x = 0, 100, 1 do
	local lighting = game:GetService("ReplicatedStorage").Lighning:Clone()
	lighting.Parent = game.Workspace
	lighting.Position = nex--line 20
	lighting.Orientation = HRP.Orientation
	if right then
		right = false
		nex = HRP.CFrame.RightVector + HRP.Position
		nex += (angle)
	else
		right = true
		nex = HRP.CFrame.RightVector + HRP.Position
		nex -= (HRP.CFrame.RightVector * 2)
		nex += (angle)
	end
end

there are no errors just when the part spawns they spawn on top of eachother and in the wrong place

Just an FYI - if you set two parts to the same position/a colliding position then one part will end up ontop of another part. On the other hand, if you set two parts to the same CFrame then they will go to the same location. I assume this is half of your problem.

To solve this, instead of doing:

I would do:

local nex = HRP.CFrame + HRP.CFrame.RightVector

And this all is to put the part to the left right? Instead of doing that I’d just do:

nex = HRP.CFrame + HRP.CFrame.RightVector * -1

This still will not work when i position the lightning it expects CFrame not vector3 on line 20 what should i do

What is the orientation of HRP to begin with? If it is facing any direction other than straight up and down then your RightVector will be facing that direction.
Also, your line 4:
local lighting = game:GetService(“ReplicatedStorage”).Lighning:Clone()
Is Lighning a spelling error?

Don’t worry about that, you can set it to CFrame instead of Position and it will work (if used with the other changes I recommended). CFrame is nice too because you don’t need to mess with orientation at all.

Change

To:

lighting.CFrame = nex

Easy right?

still no i get the same error i don’t do much cframe

Can you show the updated code?

local thun = game:GetService("ReplicatedStorage").Thunder
local TweenService = game:GetService("TweenService")

thun.OnServerEvent:Connect(function(plr, angle)
	local char = plr.Character
	local HRP = char.HumanoidRootPart
	local ray = Ray.new(HRP.Position, angle)
	local goal = {}
	goal.Position = angle

	local tweenInfo = TweenInfo.new(.1)

	local tween = TweenService:Create(HRP, tweenInfo, goal)
	tween:Play()
	local right = true
	local nex = HRP.CFrame + HRP.CFrame.RightVector
	for x = 0, 100, 1 do
		local lighting = game:GetService("ReplicatedStorage").Lighning:Clone()
		lighting.Parent = game.Workspace
		lighting.CFrame = nex
		lighting.Orientation = HRP.Orientation
		if right then
			right = false
			nex = HRP.CFrame.RightVector + HRP.Position
			nex += (angle)
		else
			right = true
			nex = HRP.CFrame + HRP.CFrame.RightVector * -1
			nex += (angle)
		end
	end
	
	local hit, position = game.Workspace:FindPartOnRayWithIgnoreList(ray, {char})
	if hit then
		print("oof")
		local Rham = hit.Parent:FindFirstChild("Humanoid")
		if Rham then
			Rham.Health -= 50
			print("hit!")
		end
	end
end)

thats all of it

I think part of the problem was that you were setting Orientation but there was no need since you’re using HRP CFrame anyway (which will set the Orientation). I made my own little test version to try to work out the bugs:

game:GetService("Players").PlayerAdded:Connect(function(pl)
	local HRP = ( pl.Character or pl.CharacterAdded:Wait() ):WaitForChild("HumanoidRootPart")
	local lightingP = game:GetService("ReplicatedStorage").Lighning
	local right = true
	local angle = Vector3.new(0, math.rad(5), math.rad(5))
		
	for x = 0, 100 do
		local lighting = lightingP:Clone()
		local nex = HRP.CFrame
		nex += nex.RightVector * (right and 5 or -5)

		-- Change this line depending on what you want angle to do, I just guessed
		nex *= CFrame.Angles(angle.X * x, angle.Y * x, angle.Z * x)
		
		lighting.CFrame = nex
		lighting.Parent = workspace
		right = not right
		wait(1)
	end
end)

Now I will say that I’m not sure what you’re using angle for in your code, so I just guessed that you wanted it to get progressively more angled. This is at least a starting point for what you intend to do.

it works just during the tween it doesn’t spawn

Are you playing the tween before running the loop? Also your tween is pretty short (0.1s), you could make it longer just to verify that the tween isn’t finishing by the time the loop is done.

i did that and now it works great thanks for your help

1 Like