Hi! So I have a spirit character that follows you around like a pet and is levitating, all the parts are cancollide off and anchored off. I have a bodyposition for the position of the spirit but for the orientation I used the standard look at cframe. It is way too jittery so is there any other way to do this?
local function Follow(HumanoidRootPart)
BodyPosition.Position = (HumanoidRootPart.CFrame * CFrame.new(2, 2, 2)).Position
part.CFrame = CFrame.new(part.Position, HumanoidRootPart.Position)
end
its because of server side lag, there will always be some latency if youâre doing stuff on the server. There is a work around though where you create the pet on the client and then send that information to the server and then back to the other clients so they can see the pet.
logic to what I mean:
client (player X) fires a remote event to the server saying they have a pet equip
The server is like âHmmm ok let me see your fileâ and gets all the information on that specific clients pet like itâs colour, mesh, size, etc.
Then the server tells everyone âYo, player X has a pet equip with this informationâ and all the other clients (player Y, Z, etc) spawn a pet with player Xâs pet information on player Xâs position
and heres pseudo some code to get you started:
--local script
local function showPet(user) --passing the user who has the pet
--initiates pet
local newPet = pet:newPet(user)
end
RunService.RenderStepped:Connect(function(step)
PetEvent:FireServer()
showPet(player) --if the player themselves has the pet, this runs it on the client
end)
PetEvent.OnClientEvent:Connect(showPet)
--server script
-- Pet remote
local function bounceRemote(player, user)
for i,v in ipairs(game.Players:GetPlayers()) do --getting all the players in the game
if v ~= player then --all players BUT the one who has the pet equip, (they already ran it on the client in the earlier code at showPet(user) after PetEvent:FireServer()
user = v
print(user)
PetEvent:FireClient(v, player)
end
end
end
PetEvent.OnServerEvent:Connect(bounceRemote)