I am trying to fix this weird bug that involves my NPC’s flying around the map for no reason. I made this script that cuts NPC’s in half (it basically takes a size value and divides it by 2), but once they get too small they float away super quickly. Been trying to fix it for over three hours, but I don’t know what to do.
Code
local model = script.Parent.Parent
local npc = script.Parent
local cd = npc.ClickDetector
local bool = Instance.new("BoolValue")
local count = 1
local tweenser = game:GetService("TweenService")
local face = npc.Head.face
local tweeninfo = TweenInfo.new(
.4,
Enum.EasingStyle.Bounce,
Enum.EasingDirection.Out,
0,
false,
0
)
function stopcollision(model)
for i, v in pairs(model:GetChildren()) do
if v:IsA("MeshPart") then
v.CanCollide = false
end
if v:IsA("Part") then
v.CanCollide = false
end
end
end
function startcollision(model)
for i, v in pairs(model:GetChildren()) do
if v:IsA("MeshPart") then
v.CanCollide = true
end
if v:IsA("Part") then
v.CanCollide = true
end
end
end
function getmodels()
local number = 0
for i, v in pairs(model:GetChildren()) do
if v:IsA("Model") then
number = number + 1
print(number.."a")
print(v)
for i, v in pairs(model:GetChildren()) do
if v:IsA("Model") then
if number >= 4 then
print("no")
v:WaitForChild("split"):Destroy()
v:WaitForChild("move"):Destroy()
v.Name = "food"
end
end
end
end
end
end
cd.MouseClick:Connect(function(hit)
getmodels()
local nclone = npc:Clone()
local function ognpch(tall, depth, width, head)
local hum = npc:WaitForChild("Humanoid")
if hum then
if not (hum:FindFirstChild("BodyHeightScale")) then
local _BodyHeightScale = Instance.new("NumberValue")
_BodyHeightScale.Name = "BodyHeightScale"
_BodyHeightScale.Parent = hum
_BodyHeightScale.Value = tall
local currentscale = _BodyHeightScale
print(_BodyHeightScale.Value)
elseif (hum:FindFirstChild("BodyHeightScale")) then
local bodyhs = hum:FindFirstChild("BodyHeightScale")
bodyhs.Value = bodyhs.Value/2
print(bodyhs.Value)
end
end
--2
if hum then
if not (hum:FindFirstChild("BodyDepthScale")) then
local _BodyHeightScale = Instance.new("NumberValue")
_BodyHeightScale.Name = "BodyDepthScale"
_BodyHeightScale.Parent = hum
_BodyHeightScale.Value = depth
local currentscale = _BodyHeightScale
print(_BodyHeightScale.Value)
elseif (hum:FindFirstChild("BodyDepthScale")) then
local bodyhs = hum:FindFirstChild("BodyDepthScale")
bodyhs.Value = bodyhs.Value/2
print(bodyhs.Value)
end
end
if hum then
if not (hum:FindFirstChild("BodyWidthScale")) then
local _BodyHeightScale = Instance.new("NumberValue")
_BodyHeightScale.Name = "BodyWidthScale"
_BodyHeightScale.Parent = hum
_BodyHeightScale.Value = width
print(_BodyHeightScale.Value)
elseif (hum:FindFirstChild("BodyWidthScale")) then
local bodyhs = hum:FindFirstChild("BodyWidthScale")
bodyhs.Value = bodyhs.Value/2
print(bodyhs.Value)
end
end
if hum then
if not (hum:FindFirstChild("HeadScale")) then
local _BodyHeightScale = Instance.new("NumberValue")
_BodyHeightScale.Name = "HeadScale"
_BodyHeightScale.Parent = hum
_BodyHeightScale.Value = head
print(_BodyHeightScale.Value)
elseif (hum:FindFirstChild("HeadScale")) then
local bodyhs = hum:FindFirstChild("HeadScale")
bodyhs.Value = bodyhs.Value/2
print(bodyhs.Value)
end
end
end
--function ends here
local function npch(tall, depth, width, head)
local hum = nclone:WaitForChild("Humanoid")
if hum then
if not (hum:FindFirstChild("BodyHeightScale")) then
local _BodyHeightScale = Instance.new("NumberValue")
_BodyHeightScale.Name = "BodyHeightScale"
_BodyHeightScale.Parent = hum
_BodyHeightScale.Value = tall
local currentscale = _BodyHeightScale
print(_BodyHeightScale.Value)
elseif (hum:FindFirstChild("BodyHeightScale")) then
local bodyhs = hum:FindFirstChild("BodyHeightScale")
bodyhs.Value = bodyhs.Value/2
print(bodyhs.Value)
end
end
--2
if hum then
if not (hum:FindFirstChild("BodyDepthScale")) then
local _BodyHeightScale = Instance.new("NumberValue")
_BodyHeightScale.Name = "BodyDepthScale"
_BodyHeightScale.Parent = hum
_BodyHeightScale.Value = depth
local currentscale = _BodyHeightScale
print(_BodyHeightScale.Value)
elseif (hum:FindFirstChild("BodyDepthScale")) then
local bodyhs = hum:FindFirstChild("BodyDepthScale")
bodyhs.Value = bodyhs.Value/2
print(bodyhs.Value)
end
end
if hum then
if not (hum:FindFirstChild("BodyWidthScale")) then
local _BodyHeightScale = Instance.new("NumberValue")
_BodyHeightScale.Name = "BodyWidthScale"
_BodyHeightScale.Parent = hum
_BodyHeightScale.Value = width
print(_BodyHeightScale.Value)
elseif (hum:FindFirstChild("BodyWidthScale")) then
local bodyhs = hum:FindFirstChild("BodyWidthScale")
bodyhs.Value = bodyhs.Value/2
print(bodyhs.Value)
end
end
if hum then
if not (hum:FindFirstChild("HeadScale")) then
local _BodyHeightScale = Instance.new("NumberValue")
_BodyHeightScale.Name = "HeadScale"
_BodyHeightScale.Parent = hum
_BodyHeightScale.Value = head
print(_BodyHeightScale.Value)
elseif (hum:FindFirstChild("HeadScale")) then
local bodyhs = hum:FindFirstChild("HeadScale")
bodyhs.Value = bodyhs.Value/2
print(bodyhs.Value)
end
end
end
--function ends here
local ogwalkspeed = npc.Humanoid.WalkSpeed
local newwalkspeed = nclone.Humanoid.WalkSpeed
--tall, depth, width, head
npch(1/3, 1/3, 1/3, 1/3)
ognpch(1/3, 1/3, 1/3, 1/3)
local ahumpart = npc.HumanoidRootPart
local newhumpart = nclone.HumanoidRootPart
local tween1 = tweenser:Create(ahumpart,tweeninfo, {Position = ahumpart.Position + Vector3.new(1,0,0)})
local tween2 = tweenser:Create(newhumpart,tweeninfo, {Position = newhumpart.Position + Vector3.new(-1,0,0)})
nclone.Parent = npc.Parent
nclone.PrimaryPart.Position = npc.PrimaryPart.Position + Vector3.new(0,0,0)
ahumpart.Position = newhumpart.Position
ahumpart.Anchored = true
newhumpart.Anchored = true
tween1:Play()
tween2:Play()
ogwalkspeed = ogwalkspeed *.5
newwalkspeed = newwalkspeed *.5
print(ogwalkspeed.."speed")
print(newwalkspeed.."speed")
face.Texture = "http://www.roblox.com/asset/?id=76690153"
nclone.Head.face.Texture = "http://www.roblox.com/asset/?id=76690153"
stopcollision(ahumpart)
stopcollision(newhumpart)
tween2.Completed:Connect(function()
newhumpart.Anchored = false
startcollision(newhumpart)
ahumpart.Anchored = false
startcollision(ahumpart)
end)
print(nclone.Parent)
count = count + 1
print(count)
end)