- What do you want to achieve? Keep it simple and clear!
I want to make the “AnotherPosition” variable be 2 studs left or right of the player’s character so I can spawn rocks there for dashes and skills and whatnot for my fighting game.
- What is the issue? Include screenshots / videos if possible!
The issue with the code that I already have is that the rocks only spawn directly 2 studs next to the character when the character is moving along the Z axis. I assume this is because I am changing the CFrame on the X axis, but I have no idea how to fix this. I’ll attach a block of code that contains the script.
- What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I’ve tried using the X value of the CFrame, the LookVector of the player, the XVector, finding the axis that the player is on with LookVector, etc. (I recognize in hindsight that some of these methods are pretty stupid, I’m not familiar with this language )
local NewRay = workspace:Raycast(Part.Position+Vector3.new(0,500,0),Vector3.new(0,-1000,0),Params)
local Y = Part.Position.Y
local NewCube = Instance.new("Part")
NewCube.CanCollide = false
if NewRay and NewRay.Instance then
NewCube.Material = NewRay.Instance.Material
NewCube.Color = NewRay.Instance.Color
NewCube.Transparency = NewRay.Instance.Transparency
Y = NewRay.Instance.Position.Y + NewRay.Instance.Size.Y/2
end
local AnotherPosition = CFrame.new(Part.Position.X,Y,Part.Position.Z)
if Direction == "Left" then
AnotherPosition = AnotherPosition * CFrame.new(2,0,0)
else
AnotherPosition = AnotherPosition * CFrame.new(-2,0,0)
end
The “Part” variable in this script is the player’s hrp. I apologize for this topic seeming somewhat trivial, I’m still relatively new to Lua (1/2 month of experience) and I am still learning. The rocks are simple baseparts who’s CFrame is set to “AnotherPosition”. Please keep in mind this script is part of a Rock/Debris Module made by @bletDemonJH, I will link the forum post he made about it below.
Thank you in advance for anyone who helps me on this topic, every comment is appreciated