I made a character change system for my game, and there’s this bug where if you’re standing near a wall or under something low and you switch to a bigger character, the new one doesn’t fit properly and ends up getting pushed through the ceiling or onto the roof.
Anyone know a good way to prevent this or handle the collision better? or maybe even some feedback on the script in general. i would really appreciate some help
Script
local ReplicatedStorage = game:GetService("ReplicatedStorage")
ReplicatedStorage.CharChange.OnServerEvent:Connect(function(player, modelName)
local model = ReplicatedStorage.Characters:FindFirstChild(modelName)
if not model then
warn("Character '" .. modelName .. "' not found!")
return
end
local newChar = model:Clone()
newChar.Name = player.Name
local humanoid = newChar:FindFirstChildWhichIsA("Humanoid")
local hrp = newChar:FindFirstChild("HumanoidRootPart")
if not humanoid then
warn("Model '" .. modelName .. "' has no Humanoid!")
end
if not hrp then
warn("Model '" .. modelName .. "' has no HumanoidRootPart!")
end
local oldChar = player.Character
local pos = CFrame.new(0, 5, 0)
if oldChar and oldChar:FindFirstChild("HumanoidRootPart") then
pos = oldChar.HumanoidRootPart.CFrame
oldChar:Destroy()
end
newChar.Parent = workspace
player.Character = newChar
newChar:MoveTo(pos.Position)
humanoid = newChar:FindFirstChildWhichIsA("Humanoid")
if humanoid then
local animateScript = model:FindFirstChild("Animate")
if animateScript then
local animateClone = animateScript:Clone()
animateClone.Parent = newChar
print("Animate script from model added to character.")
else
warn("Animate script not found in model '" .. modelName .. "'.")
end
else
warn("Humanoid not found after cloning character!")
end
end)