local pinguin = script.Parent
local speed = 10
local iceSurface = workspace.Location.Flooor.Floor1
local TweenService = game:GetService("TweenService")
local function getRandomDirection()
local angle = math.random() * math.pi * 2
return Vector3.new(math.cos(angle), 0, math.sin(angle))
end
local function movePinguin()
while true do
local direction = getRandomDirection()
local endPosition = pinguin.RootPart.Position + direction * speed
if (endPosition.X >= iceSurface.Position.X - iceSurface.Size.X / 2 and
endPosition.X <= iceSurface.Position.X + iceSurface.Size.X / 2 and
endPosition.Z >= iceSurface.Position.Z - iceSurface.Size.Z / 2 and
endPosition.Z <= iceSurface.Position.Z + iceSurface.Size.Z / 2) then
local distance = (endPosition - pinguin.RootPart.Position).Magnitude
local travelTime = distance / speed
local tweenInfo = TweenInfo.new(travelTime, Enum.EasingStyle.Linear)
local tween = TweenService:Create(pinguin.RootPart, tweenInfo, {CFrame = CFrame.new(endPosition)})
tween:Play()
tween.Completed:Wait()
end
wait(1)
end
end
movePinguin()
So here I have a basic
script for penguin movements, I want it to move randomly on the ice, but for some reason it doesn’t work although there are no errors, rootPart has no anchor, but others do, all parts are attached via bone. What is wrong?
