Hello, in one of my games there is a script where a remote event is fired in a run service loop, and I was wondering if that could be making the game lag
The code is something like this
local RunService = game:GetService("RunService")
local Player = game:GetService("Players").LocalPlayer
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Event = ReplicatedStorage.Event
RunService.Heartbeat:Connect(function()
local Speed = Player.Character.PrimaryPart.AssemblyLinearVelocity.Magnitude
Event:FireServer(Speed)
end)
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Event = ReplicatedStorage.Event
Event.OnServerEvent:Connect(function(Player, Speed)
Player.Character.SpeedSound.PlaybackSpeed = Speed / 450
end)