I’m working on a Dark Souls like game and I’m trying to make a different form of combat to better fit the game. Basically the arm follows the mouse and that’s how you swing a weapon, there’s going to be more but I have yet to implement it. The problem is the arm doesn’t keep up with the player, it “snakes” behind them.
I’ve got 2 scripts for the client and the server.
this is the first local script, located under StarterPlayerScripts
local Attack = true
wait(1) -------I haven't fully completed the script yet but I want to get the base of it working
if Attack == true then
local TimePassed = 0
game:GetService("RunService").RenderStepped:Connect(function(TimeThing)
local mouse = game.Players.LocalPlayer:GetMouse()
local EndPos = mouse.Hit
local StartPosX = 0
local StartPosY = 0
local EndPosX = 0 ----here are a bunch of things for some slope math I'll add later
local EndPosY = 0
local mousedown = false
mouse.Button1Down:Connect(function(mosuee)
StartPosX = mouse.X
StartPosY = mouse.Y -----These are here because if the player clicks something different will happen, but I haven't implemented it yet
mousedown = true
end)
mouse.Button1Up:Connect(function(asdsadasda)
EndPosX = mouse.X
EndPosY = mouse.Y --same thing as above. again I just want to get the base of the system working before I add the other stuff
mousedown = false
end)
TimePassed = TimeThing + TimePassed ----this is so the remote event won't fire too much
if TimePassed >= game.Players.LocalPlayer:FindFirstChild("WeaponWeight").Value then
TimePassed = 0
game.Players.LocalPlayer.Character:FindFirstChild("Right Arm").Massless = true
game.Players.LocalPlayer.Character:FindFirstChild("Right Arm").Anchored = true --- I tried making the arm owned by the client but because you can't change a parts network ownership when it's anchored I tried moving the anchor to the client, it didn't work but I didn't really have a reason to move the anchor back to the server
game.ReplicatedStorage.RemoteEvents.RotatePlayerArm:FireServer(EndPos,StartPosX,StartPosY,EndPosX,EndPosY,mousedown)
end
end)
end
that first script could be the one creating the problem with network ownership and client-server spaghetti
second script is a server script located in StarterCharacterScripts
local TS = game:GetService("TweenService") --I use tweening because the remote event fires around 10 times a second, so tweening the spaces in-between keeps it smooth
game.ReplicatedStorage.RemoteEvents.RotatePlayerArm.OnServerEvent:Connect(function(player, Hit, SXP, SYP, EXP, EYP, MouseDown)
local Torso = player.Character:FindFirstChild("Torso")
local Left = player.Character:FindFirstChild("Right Arm") ---I know the name says left but that's because originally I used the left arm
Left:SetNetworkOwner(player) ---this line is pretty much useless because nothing changed
if Torso:FindFirstChild("Right Shoulder").Enabled == true then --so it won't disable the shoulder repeatedly
Torso:FindFirstChild("Right Shoulder").Enabled = false
player.Character:FindFirstChildWhichIsA("Humanoid").RequiresNeck = false
-------this is where I put the anchoring line before I moved it to the local script
end
Left.AssemblyLinearVelocity = Vector3.new(0,0,0) --even though the arm is anchored I added this just incase
Left.AssemblyAngularVelocity = Vector3.new(0,0,0)
local i = TweenInfo.new(
player.WeaponWeight.Value, --I forgot to mention that 'WeaponWeight' determines how delayed you swing your weapon, right now I have it at the fastest value so it shouldn't be an issue
Enum.EasingStyle.Linear,
Enum.EasingDirection.Out,
0,
false,
0.00)
local goals = {CFrame = CFrame.lookAt(Torso.Parent.ArmCube.Position, Hit.Position, Vector3.new(0,1,0)) *CFrame.Angles(math.rad(90),0,0)}
local tweeeem = TS:Create(Left,i,goals)
tweeeem:Play()
-- Left.Position = Torso.Parent.ArmCube.Position ---i tried adding this line but it didn't help
end)
At first I thought the tween was the issue, but the arm rotates with the mouse perfectly so that can’t be it. I suspect it has something to do with network ownership but I know barely anything about it. I tried parenting the arm to the workspace because sometimes the player’s model can cause issues but that didn’t help. If I unanchor the arm then it falls through the floor and then teleports back up. if you can help or even just suggest what the problem is then that would be great. Thanks!