How do I eliminate this wait without sacrificing this code functioning?

So I’ve been having this problem In my game where I spawn players on something and sometimes they dont rotate correctly so I figured out Id just have to remove their character before spawning them and that worked but the problem is that, it isnt instant and players can still move a bit just before but I dont want them able to move though

The problem is in the first if block, it works but I want it to be faster though so players cannt possibly move before I put them on the blocks, basically its that second wait of .01 seconds, I could remove it but it just wont allow the two lines of code after it to work because I think the player just hadnt had enough time to load

local character = player.Character
	
if character then
	RemoteManager.MenuCamera:FireClient(player)
	player.Character = nil
	character.Parent = nil
	task.wait(1)
	player:LoadCharacter()
	
	local newCharacter = player.Character
	local block = self.blocks:GetChildren()[index].PrimaryPart
	newCharacter:PivotTo(block.CFrame + Vector3.new(0,4,0))
	task.wait(.01)
	RemoteManager.BlockStart:FireClient(player)
	self:DisableMechanics()
else
	player:LoadCharacter()
	local block = self.blocks:GetChildren()[index].PrimaryPart
	player.Character:PivotTo(block.CFrame + Vector3.new(0,4,0))
	RemoteManager.BlockStart:FireClient(player)
end
2 Likes

use

local character = player.Character or player.CharacterAdded:Wait()
2 Likes

Alright so i replaced the newCharacter with that but it didn’t work also the first character variable is me checking if there is a character I haven’t destroyed it yet

try using wait(0.00001) instead

1 Like

I tried this aswell but sadly I think its just too small of a time and it just isnt enough for the character to finish loading and it just doesnt work, i appreciate the help

I ended up having a character added event on the client and just having the player disable the mechanics, but the animation isnt working inside of the character added event though…

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