Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

What can be a good alternative for RenderStepped that can be used in Server Scripts?

Asked by 3 years ago

Hello! I have been making a FPS framework and I have encountered this problem. If I use Stepped, Heartbeat or a while loop for my Server Handler, the gun seems to lag behind while the player is moving. RenderStepped works fine but it can only be used in local scripts. How can I fix this? Here's my code:

local RS = game:GetService("ReplicatedStorage")
local Run= game:GetService("RunService")
local UIS = game:GetService("UserInputService")
local Tservice = game:GetService("TweenService")

local players = game:GetService("Players")

local MainCframe = CFrame.new(0.8,1,-0.7)

local function Equip(cam, primary)
    for i, player in pairs(players:GetPlayers()) do
        local GunClone = RS:WaitForChild("GunModels").Server.M4A1:Clone()
        local character = player.Character or player.CharacterAdded:Wait()
        character["Left Arm"].Transparency = 1
        character["Right Arm"].Transparency = 1
        GunClone.Parent = character
        Run.Heartbeat:Connect(function()
            GunClone:SetPrimaryPartCFrame(character.Torso.CFrame * MainCframe)
        end)
    end
end

RS:WaitForChild("Events").Equip.OnServerEvent:Connect(Equip)

It is not finished though.

Thing's I tried:

Searching online - I did not find anything helpful, Trying to use Bind to render stepped - I failed because I have no idea to use it.

1 answer

Log in to vote
0
Answered by 3 years ago

There is no server-sided equivalent to RenderStepped (now called PreRender). RenderStepped fires every frame before rendering, and the server does not render anything, which is why it's client-sided in the first place.

Most people use RemoteEvents connected to RenderStepped to bypass this, like so:

-- goes in a local script
game:GetService("RunService").RenderStepped:Connect(function()
    RemoteEvent:FireServer(arg1, arg2...)
end)

-- goes in a server script
RemoteEvent.OnServerEvent:Connect(function(player, arg1, arg2...) -- first argument is always the player that fires the event
    -- do stuff
end) 

Read the documentation on RunService here and the documentation on RemoteEvents.

0
Thanks! I understand now. RazorXX2 24 — 3y
Ad

Answer this question