Attacks go to some random direction off to the side while moving backwards

This is something I’ve never really had an issue with throughout my years of working on fighting games on Roblox up until recently with this latest project I’m working on, essentially this game (like all the other fighting games I’ve worked on admittedly) uses attacks that create objects used as projectiles to be hurled towards your enemies like bones and whatnot.

The problem with this though is that if I were to be moving backwards while using these attacks (Shiftlock, first person), for some odd reason that I have yet to figure out, the attacks will go wildly off course and just fly off to the left or right rather than straight ahead of the player as it should be going.

The odd thing about this is that, as stated before this has never happened with any of my other fighting games I’ve worked on, even the one I’ve made all the way back in 2020. This game even reuses code from the last fighting game I’ve worked on for it’s attack creation system albeit more optimized, but I do not think the optimizations are what’s causing this because even before that the attacks still behave like this in the game for some reason.

Even stranger is that if I go back to one of those old fighting games and try using an attack while moving backwards, it won’t fly off in some left/right direction?

Here is the code for one of the attack Tools:

active = 1
ogName = script.Parent.Name
script.Parent.Activated:Connect(function()
	if active == 1 then
		active = 0
		local g = game.ServerStorage.attacks["Sans"].Bone:Clone()
		g.owner.Value = script.Parent.Parent
		g.Parent = workspace
		g.PrimaryPart = g.Head
		g:PivotTo(script.Parent.Parent["HumanoidRootPart"].CFrame * CFrame.new(0,0,0))
		local cd = script.Parent.cd.Value
		local origcd = cd
		for i = 1,cd do
			script.Parent.Name = cd/(script.Parent.division.Value)
			task.wait(1/(script.Parent.division.Value))
			cd-=1
		end
		cd = origcd
		script.Parent.Name = ogName
		active = 1
	end
end)

At first I tried changing the Torso from HumanoidRootPart before settling on this change permanently after a friend told me that that would be a more optimized way of handling the attack creation, it didn’t seem to change a thing about what direction the attack goes when moving backwards.

I even took out the Angles part of the PivotTo() code, that didn’t seem to change anything either.

If there is a solution to this, then I do hope it’s something simple like using the Replace All feature in studio or something along the lines of that simplicity because so far I have made like 200+(?) attack Tools for the game and I would go insane manually going through every single one of those, but if it isn’t then I will still try to implement it because I do really want to get this fixed.

Any and all help with this problem will be greatly appreciated, thank you ! ^ ^

-= KNOWN LEADS =-

More information regarding the issue (I am putting this here because I realize it would be more productive to include this in the main post rather than in the replies, my apologies); I have discovered that the attacks do not veer off to the left or right while moving backwards when I am just my unaltered Player model, they also do not do this whenever I am using a traditional morph where you step on a pad.

The attacks do that whenever I am inside of a character model morph stored in a folder inside of ReplicatedStorage, I am able to go into this morph because of a character selection GUI that I had programmed with the help of this YouTube video: https://www.youtube.com/watch?v=UlU80sZSN0g)

Now that I know what specifically is causing this, now I need to figure out how to get it to stop veering the attacks off to the left/right whenever I am inside of this morph because it is crucial that I keep the character selection GUI for the game. I have tried replacing the Noob NPC with a version of my own Player model that had everything non-vital stripped away to put onto the morph pad to then put inside of ReplicatedStorage since I figured the inner workings would be far more accurate than the Noob NPC. Unfortunately this provided the same results as the morph with the Noob NPC as the base.

I’ve also tried doing other various things like copypasting the RootJoint from my Player model to replace the one inside of the morph’s HumanoidRootPart to see if that would change anything, nope.

While I do think I’ve made a huge breakthrough on what’s causing this, I’m still unsure as to how I’m going to be able to fix this as it doesn’t seem to be anything script-wise, the ReplicatedStorage morph itself is barely any different from if I were to just go onto the pad to morph.

The long and short of it: The attacks are going in left/right directions while moving backwards because they are being used while I am inside of a morph from a folder inside ReplicatedStorage after selecting a character on the character selection GUI. I need to figure out what I need to do in order to get the attacks to stop veering off left/right while inside of this morph.

I think that the issue doesn’t lie within :PivotTo() or the projectile itself, I think it’s the direction being used here. When moving backwards in shiftlock or first person, the HumanoidRootPart can rotate slightly while the camera stays stable, which causes projectiles fired using the character’s CFrame to veer left or right. These shifts are pretty subtle but do impact your projectiles at a large scale. Using the camera’s look direction on the client and sending that to the server is what I would try and do here.

Here’s an example of what I am trying to get at:

Client (Inside the Tool):

local Player = game.Players.LocalPlayer
local Camera = workspace.CurrentCamera
local Remote = game.ReplicatedStorage.FireAttack

script.Parent.Activated:Connect(function()
    local Origin = Player.Character.HumanoidRootPart.Position
    local Direction = Camera.CFrame.LookVector
    
    Remote:FireServer(Origin, Direction)
end)

Server:

local Remote = game.ReplicatedStorage.FireAttack

Remote.OnServerEvent:Connect(function(Player, Origin, Direction)
    local g = game.ServerStorage.attacks.Sans.Bone:Clone()
    g.Parent = Workspace
    g.PrimaryPart = g.Head
    
    g:PivotTo(CFrame.new(Origin, Origin + Direction))
    
    g.PrimaryPart.AssemblyLinearVelocity = Direction * 120
end)

Goodluck!

1 Like

Ok I do understand the Client part for the most part, but how would I go about implementing the Server part of the code though?

Also I did do my best to implement the code that you sent me, and I’m not quite sure if I implemented it correctly because when I went to go test it the bone would just fire downward into the ground at an angle, direction-wise I’m not quite sure if it helped.

Again I’m still not quite sure how to implement this code so I might have messed something up along the way.

It’s hard to code something when I don’t have much context and just a script. But to exaplin, the client is supposed to fire to the server and let the server know the HumanoidRootPart’s Position, and the Camera’s LookVector. Then, I wrote a server script to handle the Origin and Direction and g is supposed to be the bone but again I don’t really know what that model looks like or even what that is so it’s hard to code something with no context.

Though g:PivotTo(CFrame.new(Origin, Origin + Direction)) and g.PrimaryPart.AssemblyLinearVelocity = Direction * 120 should work.

Maybe if you could provide a RBXM file that would help me out too, though its a little weird you’re having these issues since you said your script has worked in pervious games.

1 Like

That is fair, essentially what I’m working with right now to hopefully kick things off for the rest of the attacks is a Bone Throw attack that creates a bone that moves forward in front of the Player.

Also I did try the Origin, Origin + Direction thing in place of what I currently have for PivotTo(), but that made the bone shoot downward into the floor at an angle.

The Bone’s model itself essentially consists of just the bone itself and the Head part physically, inside are values and scripts, also a script inside the bone itself but that just handles the damage so that’s irrelevant.

Here is what the important script inside the bone model looks like:

script.Parent.delete.Disabled = false --Triggers a script inside the bone model that deletes it after a while
while true do
	script.Parent.Head.CFrame *= CFrame.new(0,0,-2) - Propels the Head part forward in front of the Player
	script.Parent.bone.CFrame *= CFrame.fromEulerAnglesXYZ(0,0,-0.3) --Rotates the Bone itself
	script.Parent.bone.Position = script.Parent.Head.Position --Puts the Bone wherever the Head part is at
	task.wait()
end

Also I’m not so sure about the AssemblyLinearVelocity part since:

  1. I do already have movement handled within the bone model itself as I just showed
  2. There are some attacks I’ve made that are stationary like blaster attacks, all I really need is a way to get the attacks to stay straight in front of the player while moving backwards with shiftlock and/or first person

Okay I kinda see what’s happening here a little bit better now. What I’d try now instead is spawning the bone using the camera’s look direction but flattening it so it stays level, then letting your existing loop handle the movement.

On the server, I feel like we should build a look CFrame using only X and Z from the direction, pivot the model once, and don’t touch its movement after that. That way the bone’s “forward” stays correct, and the CFrame *= CFrame.new(0, 0, -2) logic will move it straight every time, even while moving backwards.

Server:

local Remote = game.ReplicatedStorage.FireAttack

Remote.OnServerEvent:Connect(function(Player, Origin, Direction)
    Direction = Vector3.new(Direction.X, 0, Direction.Z)
    if Direction.Magnitude == 0 then return end
    Direction = Direction.Unit
    
    local Bone = game.ServerStorage.attacks["Sans"].Bone:Clone()
    Bone.Parent = game.Workspace
    Bone.PrimaryPart = Bone.Head
    Bone:PivotTo(CFrame.lookAt(Origin, Origin + Direction))
end)

Try that, hopefully that helps!

1 Like

Ok I still don’t understand what you mean by Server, like it looks drastically different from what I’ve been working with and I don’t know if I’m supposed to put it in the Tool’s script or make a whole new script and put it elsewhere, especially with all that Remote stuff.

Anyway I did try this new code to the best of my ability by factoring in code from what you just sent me and earlier code you sent me to complete the current code you sent me, the bone does not go down towards the floor anymore but it does go in a stagnant direction no matter where I’m facing.

The Server part is a server script that should be placed inside ServerScriptService which handles a remote event that should be placed inside of ReplicatedStorage. And yes, I agree is does look different but I am just working on the actual direction of the bone and not setting it up on my end since you already did that here:

And no, don’t put the server part inside the tool, the tool script that I worked on a bit is this part:

Lastly, could you provide a GIF/Video that showcases what this looks like since I am a little confused myself.

1 Like

The attack itself is simple, all it does is make a spinning bone go forward.

Also the Player part of the code doesn’t work, whenever it gets to the Player.Character part the console says assigned nil to Character, so I have to replace Player.Character with script.Parent.Parent since that links back to the Player holding the tool anyway.

Also just now it’s saying FireServer can only be called from the client despite being inside the Tool script? Even then, am I supposed to just make a new server script in ServerScriptService for every attack in the game? Because from the looks of it that code for the server script seems to only account for that specific attack.

Also how do I get the remote to fire off that specific script? If I am supposed to make a script for every individual attack I’m not really sure how I get the script to call on that specific script for that specific attack if that is the case.

Bumping this post since I do still need help with this issue

UPDATE: I have made a discovery to this issue; so I made a separate place using some assets from the fighting game to see if it was just an issue of the place itself, at first I tried it without the morph and the attacks did not shift direction at all when moving backwards.

But when I went to go select a morph, that’s when the attacks suddenly began shifting direction whenever I fired them off

So from what I could gather, it isn’t the fault of how the attack spawning is programmed or the player itself, it appears to be the morphs causing this shift in direction.

Now mind you, this game doesn’t use the traditional morphing that most games use like stepping onto a pad and turning into that morph, instead this game uses a character selection GUI where if you select a morph it will replace your current character with that character model.
(Special thanks to this video for helping me program that ! https://www.youtube.com/watch?v=UlU80sZSN0g)

So I do believe that the character model of the morph may be missing a key component to the Player itself that’s causing the attacks the shift off course, I will be conducting further investigation into this and hopefully I will be able to find a solution to this.

I also did try testing out the traditional button pad morph to see if anything would change, it also worked perfectly fine.

So this confirms that this new way of morphing the character does have something to do with the attacks going off-course, unfortuantely I have yet to figure out the main cause of this with this specific morphing method.

UPDATE #2: I have tried copying my own player model, stripping it of it’s hats, accessories, everything that isn’t vital to the character model itself. I put it onto the morph button (That’s how I make all the characters for the fighting game) and put it into the character morph folder where the character select gets it’s morphs from.

I tested it out to see if that would do anything: nope. It still causes the attacks to go flying off in some left/right direction whenever I move backwards. I honestly don’t know what in the morph (in the character select) could possibly be making the attacks behave this way whenever I move backwards.

I will try one more thing; I will try anchoring the HumanoidRootPart itself and then when it spawns and gets put into the Workspace it’ll unanchor because maybe it’s because it being unanchored in the folder is somehow causing an imbalance with the character model itself and that’s what’s causing the attacks to go in different directions when moving backwards? This is highly unlikely though, I’m just desperate to try and find an answer to this oddity once and for all.

If this does work, I will let yall know and set that as the solution, but if it doesn’t then I will simply not say anything because I do feel like I might be flooding this thread with my replies.

UPDATE #3: I have opted to put my current findings onto the main post rather than just replying them, sorry about that x.x

If you could, please do read the main post to get a good idea as to what I am currently working with in terms of this issue. Thank you !

Did you try to anchor the script? maybe that would kinda help

1 Like

Anchor the script? I don’t really understand what you mean by that, I don’t think scripts can be anchored unless I’m mistaken?

Anchoring a script enables the physical properties of the calculated momentum and velocity of its predecessor.

1 Like

I see, but I’m not really seeing an option to anchor the script anywhere. When I try to anchor it through the Studio UI, it just greys it out and won’t let me. I also don’t see any Anchor property inside the Script either.

Do I need to anchor the script manually by tying in Script.Anchored = true?

Hmm.. that’s weird. It shows up for me.

1 Like