Game attack holder

Hey everyone, so im making a anime game and in my game to do some attack you have to press your key and then release it.When you press it and its down your character will follow the mouse so i made it but like the way i made it isnt smooth and i would like to know if there is better way to make it
How i made it :
Server has a RunService.Heartbeat and ask every frame to the client his mouse position and then rotate the character
Result :
robloxapp-20230715-1216367.wmv (1.1 MB) ( this is not really smooth and it increase player ping)

2 Likes

What do you mean by it’s not smooth? Clearly, in the document you provided, the character is smoothly following where the mouse is

1 Like

No its just because of the video quality but I saw a lot of game that was way smoother than mine, and when I jump and press my key it’s bring me down because of latency

1 Like

What if you were to rotate the player locally, that way there shouldnt be any apparant delays.

It may also help with some potential lag from the server recieving data from the client every frame like you said.

You could do this by the server sending a FireAllClient() to start the rotation, and then once more to stop the rotation.

1 Like

Yeah, if it’s the case then you can use HumanoidRootPart.CFrame:Lerp()
And i know a way to use it efficieny

So bascially, all you need to do is having a remoteEvent but in this case, you definitely already have one. So, make the local script loops with a function of firing the remoteEvent sending server scripts the mouse positions. Example :

local REvent = somewhere -- the remoteEvent
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local skillBoolean = false -- this is a boolean for checking if the skill set is being perform, but if you don't have this, i recommend you to have it
local mouse = player:GetMouse()
-- a function to detect whenever player pressed key down to trigger the skill set
skillbolean = true
repeat
     REvent:FireServers(mouse.Hit,character:WaitForChild("HumanoidRootPart"))
     wait(0.1)
until  skillBoolean == false -- stop when player finished the skill set, normally, you can set this to false after a specific amount of time
-- end)

fix typo errors if you encountered one in my script, but basically it’s a example so

And for the server script :

local REvent = somewhere -- the remoteEvent
local RS = game:GetService("RunService")
REvent.OnClientEvent:Connect(function(plr, mouseCF, humanoidRPT)
    local connection = RS.Stepped:Connect(function()
         humanoidRPT.CFrame = humanoidRPT.CFrame:Lerp(CFrame.new(humanoidRPT.Position,mouseCF.Position),0.2)
    end)
    local waitTime = 0 -- change the wait time if you want
    task.delay(waitTime,function()
        connection:Disconnect()
    end)
end)

I tried similar methods in my own personal game, and if you have a stable internet connections, this wouldn’t cause too much of a ping-rise, but if your internet connections is unstable, you probably would get around 50-300 ping base on how many people are performing it and how unstable your internet connection is

However, as i progress through my game developments, i find this method performance is very poor. If you willing to spend your entire day sit on a chair and fix random bugs, this method would fit

1 Like

I will try making it server side and client side in the same time so everyone see him rotate and for the client it will be very smooth

1 Like

Here is the solution guys to make it really smooth and without latency , use AlignPosition and AlignOrientation
image

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.