Hey there, i’ve been trying so hard to just tween a Part’s size in one direction for my Slime enemy, and it just refuses to work. I’m trying to make a squash and stretch idle animation loop, as well as a squash (charge) then stretch (fire) for a Fire attack where he shoots a projectile out his mouth. But it just won’t work, i’ve been trying so hard to just make it work and when it does work other issues appear, it’s really complicated. I’ve looked around the DevForum, not much has worked. Please HELP (it’s specifically self._Base that needs to be tweened). I honestly don’t get why there isn’t a built-in way to tween in only one side.
--||Service(s)
local ReplicatedStorage : ReplicatedStorage = game:GetService("ReplicatedStorage")
local TweenService : TweenService = game:GetService("TweenService")
local RunService : RunService = game:GetService("RunService")
local Players : Players = game:GetService("Players")
local Debris : Debris = game:GetService("Debris")
--||Variable(s)
local Player : Player = Players.LocalPlayer
local Character : Model = Player.Character or Player.CharacterAdded:Wait()
local Root : BasePart = Character:WaitForChild("HumanoidRootPart")
local Camera : Camera = workspace.CurrentCamera
--------------------------------------
local Animations = ReplicatedStorage:WaitForChild("Animations")
local Utilities = ReplicatedStorage:WaitForChild("Utilities")
local Effects = ReplicatedStorage:WaitForChild("Effects")
local Events = ReplicatedStorage:WaitForChild("Events")
local Sounds = ReplicatedStorage:WaitForChild("Sounds")
--------------------------------------
local Functions = require(Utilities.Functions)
local Constants = require(Utilities.Constants)
--------------------------------------
local Slimebots = {}
local Slimebot = {}
Slimebot.__index = Slimebot
--------------------------------------
local function UpdateCharacterVariables() --Do NOT remove this code, if u do, the obstacle will not work anymore once the player resets.
Character = Player.Character or Player.CharacterAdded:Wait()
Character:WaitForChild("HumanoidRootPart")
--------------------------------------
Root = Character:WaitForChild("HumanoidRootPart")
end
--------------------------------------
UpdateCharacterVariables()
--------------------------------------
Player.CharacterAdded:Connect(function()
task.wait(0.1) --Delay a lil to make sure everything is loaded first
--------------------------------------
UpdateCharacterVariables()
end)
--------------------------------------
function Slimebot.New(Model: Model)
local self = setmetatable({}, Slimebot)
self._Model = Model
self._Hitbox = Model:WaitForChild("Hitbox")
self._Base = Model:WaitForChild("Base")
self._Splat = Model:WaitForChild("Splat")
self._Eye = Model:WaitForChild("Eye")
self._Mouth = Model:WaitForChild("Mouth")
self._OGCFrame = self._Base.CFrame
self._OGSize = self._Base.Size
self._TimerStarted = false
self._State = "Idle"
--------------------------------------
table.insert(Slimebots, self)
--------------------------------------
task.spawn(function()
while true do
if self._State == "Firing" then
task.wait()
--------------------------------------
continue
end
--------------------------------------
local Distance = (self._Base.Position - Root.Position).Magnitude
--------------------------------------
if Distance < Constants.CLASS_DISTANCE_CHECK + 40 then
Functions:PlayTween(self._Base, TweenInfo.new(.75, Enum.EasingStyle.Sine), {Size = Vector3.new(4.5, 4, 4.5), Position = self._Base.Position - Vector3.new(0, 2, 0)})
Functions:PlayTween(self._Splat, TweenInfo.new(.75, Enum.EasingStyle.Sine), {Size = Vector3.new(10, 0.001, 11)})
Functions:PlayTween(self._Eye, TweenInfo.new(.75, Enum.EasingStyle.Sine), {Size = Vector3.new(0.75, 0.5, 0.001)})
Functions:PlayTween(self._Mouth, TweenInfo.new(.75, Enum.EasingStyle.Sine), {Size = Vector3.new(2.5, 0.5, 0.001)})
--------------------------------------
task.wait(.75)
--------------------------------------
Functions:PlayTween(self._Base, TweenInfo.new(.75, Enum.EasingStyle.Sine), {Size = Vector3.new(4.5, 4.5, 4.5), Position = self._Base.Position + Vector3.new(0, 2.25, 0)})
Functions:PlayTween(self._Splat, TweenInfo.new(.75, Enum.EasingStyle.Sine), {Size = Vector3.new(9, 0.001, 10)})
Functions:PlayTween(self._Eye, TweenInfo.new(.75, Enum.EasingStyle.Sine), {Size = Vector3.new(0.5, 1, 0.001)})
Functions:PlayTween(self._Mouth, TweenInfo.new(.75, Enum.EasingStyle.Sine), {Size = Vector3.new(2, 1, 0.001)})
--------------------------------------
task.wait(.75)
end
--------------------------------------
task.wait()
end
end)
--------------------------------------
return self
end
--------------------------------------
function Slimebot:Fire()
self._State = "Firing"
--------------------------------------
--Tween the Size (squash down and then stretch back up)
--------------------------------------
task.wait(4)
--------------------------------------
self._State = "Idle"
end
--------------------------------------
RunService.Heartbeat:Connect(function(DT)
for i = #Slimebots, 1, -1 do
local Obj = Slimebots[i]
--------------------------------------
if Obj._State == "Firing" then
continue
end
--------------------------------------
local Distance = (Obj._Hitbox.Position - Root.Position).Magnitude
--------------------------------------
if Distance <= 40 then --Different distance check. Play tweens when player is close, make slimebot look at player when they're even closer.
if Obj._State == "Idle" then
Obj._State = "Looking"
--------------------------------------
Obj._TimerStarted = false
end
--------------------------------------
local Direction = (Root.Position - Obj._Base.Position).Unit
--------------------------------------
Direction = Vector3.new(Direction.X, 0, Direction.Z).Unit
--------------------------------------
Obj._Base.CFrame = Obj._Base.CFrame:Lerp(CFrame.lookAt(Obj._Base.Position, Vector3.new(Root.Position.X, Obj._Base.Position.Y, Root.Position.Z)), 0.125)
--------------------------------------
if not Obj._TimerStarted and Obj._State ~= "Firing" then
Obj._TimerStarted = true
--------------------------------------
task.spawn(function()
task.wait(math.random(2, 4))
--------------------------------------
if Obj._State == "Looking" then
Obj:Fire()
end
--------------------------------------
Obj._TimerStarted = false
end)
end
else
if Obj._State ~= "Firing" then
Obj._State = "Idle"
end
end
end
end)
--------------------------------------
return Slimebot