How do I convert this code to use Tween Service instead? I have tried doing it myself but kept getting errors instead…
local RS = game:GetService("ReplicatedStorage")
local remote = RS:WaitForChild("sizeRemote")
local Twen = game:GetService("TweenService")
remote.OnServerEvent:Connect(function(player)
local char = player.Character
local hum = char:WaitForChild("Humanoid")
local originalHeadScale = hum.HeadScale.Value
local originalBodyDepthScale = hum.BodyDepthScale.Value
local originalBodyWidthScale = hum.BodyWidthScale.Value
local originalBodyHeightScale = hum.BodyHeightScale.Value
for i = 0, 1, 0.1 do
hum.HeadScale.Value += i
hum.BodyDepthScale.Value += i
hum.BodyWidthScale.Value += i
hum.BodyHeightScale.Value += i
task.wait()
end
wait(3)
hum.HeadScale.Value = originalHeadScale
hum.BodyDepthScale.Value = originalBodyDepthScale
hum.BodyWidthScale.Value = originalBodyWidthScale
hum.BodyHeightScale.Value = originalBodyHeightScale
end)
local char = plr.Character or plr.CharacterAdded:Wait()
for _,v in pairs(char:GetChildren()) do
if v:IsA("BasePart") then
game:GetService("TweenService"):Create(v,TweenInfo.new(1),{property}):Play()
end
end
Roughly TweenService can only tween properties with Tweenable methods. Such as numbers, colors, sizes, etc.
I suggest you check documentation whilst reading from the example shown above.
TweenService has a function called Create; you can construct tweens with it.
It takes three arguments; the first one is the Instance object whose properties you want to tween, and the second is a TweenInfo with which features you could tween (such as duration). The third one is a table of properties you want to tween.
Humanoid object has some NumberValues that determine the scale of the body parts, and those values should be the first argument of the Create function. Despite the fact that this could be done individually for each value, you can store the name of each one in a table and loop through them.
As a micro-optimization, I used the coroutine library as well. While it loops through the elements in the table, you could create threads via coroutine.wrap() function. Threads run separately from the code execution flow, meaning you could create a tween for the next NumberValue while the current one gets done.
The name of each NumberValue is stored as an index; their values are the original Value property before the property changes. Whenever you want to default the values, you could loop through the same table and assign the values as the values in the table are original.
Here is the intended script.
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TweenService = game:GetService("TweenService")
local remoteEvent = ReplicatedStorage:WaitForChild("sizeRemote")
local originalHeadScale = 1
local originalBodyDepthScale = 1
local originalBodyHeightScale = 1
local originalBodyWidthScale = 1
local humanoidValues = {
["HeadScale"] = originalHeadScale,
["BodyDepthScale"] = originalBodyDepthScale,
["BodyHeightScale"] = originalBodyHeightScale,
["BodyWidthScale"] = originalBodyWidthScale
}
local TInfo = TweenInfo.new(1)
remoteEvent.OnServerEvent:Connect(function(player)
local char = player.Character
local Humanoid = char:WaitForChild("Humanoid")
if char then
for valueName, originalValue in pairs(humanoidValues) do
local thread = coroutine.wrap(function()
local tween = TweenService:Create(Humanoid[valueName], TInfo, {Value = 6.5})
tween:Play()
end)
thread()
end
task.wait(3)
for valueName, originalValue in pairs(humanoidValues) do
Humanoid[valueName].Value = originalValue
end
end
end)
Please tell me if you encounter any issues or demand advice. There are much more things I didn’t explain, but this will help you understand a little.
local char = plr.Character or plr.CharacterAdded:Wait()
local sizeX = 5
local sizeY = 5
local sizeZ = 5
spawn(function()
for _,v in pairs(char:GetDescendants()) do
if v:IsA("BasePart") then
game:GetService("TweenService"):Create(v,TweenInfo.new(1),{Size = Vector3.new(sizeX, sizeY, sizeZ)}):Play()
end
end
end)