I am attempting to make a script that makes a player’s character (A ball,) bigger when you touch parts. This works, all until you get to the size limit, stated in the script which is 35. You can see in the video, shortly after I reach the size level for my character, not the leaderstat, the ball starts to shake and move rapidly all around the map. Take into consideration that I am not clicking any keys on my keyboard or moving my mouse while this is happening. Anyone please explain how to fix. (Also the script isn’t mine and I want the ball’s physics to remain the same even when the size changes.)
Here is the script:
game.Players.PlayerAdded:Connect(function(player)
player:WaitForChild("leaderstats"):WaitForChild("Size").Changed:Connect(function()
local size = player.leaderstats.Size.Value
-- Find the player's character
local character = player.Character
if character then
local ball = character:FindFirstChild("Head") -- Replace "Head" with your ball part name
if ball and ball:IsA("BasePart") then
-- Calculate new size
local newSize = Vector3.new(size, size, size) / 5000 + ball.Size
local originalMass = ball:GetMass()
-- Compare individual components of Vector3
if newSize.X < 35 and newSize.Y < 35 and newSize.Z < 35 then
ball.Size = newSize -- Set the size of the ball
-- Adjust density to maintain original mass
local newDensity = originalMass / (newSize.X * newSize.Y * newSize.Z)
local originalFriction = ball.CustomPhysicalProperties.Friction
-- Reapply original friction and set new density
ball.CustomPhysicalProperties = PhysicalProperties.new(newDensity, originalFriction, 0.5)
else
end
end
end
end)
end)
Here is the video (Google Drive link):