Hi, I’m doing a game in which the dummies supposedly fall with the Bounce animation, but after a few hours I only got this
(Sorry I don’t know how to upload gif here)
All parts seems to be welded, here is the code
local x = math.random(-192, -166)
local z = math.random(187, 213)
local pos = CFrame.new(x, 200, z)
local dummy = game.StarterGui.plr.Dummy.Models.Start:Clone()
dummy.Parent = workspace.Dummys.Start
dummy:SetPrimaryPartCFrame(pos * CFrame.Angles(0, math.random(1,360), 0))
dummy.Name = "d1"
local primary = dummy.PrimaryPart
for _, part in pairs(dummy:GetChildren()) do
if (part ~= primary) then
local weld = Instance.new("WeldConstraint")
weld.Part0 = part
weld.Part1 = primary
weld.Parent = part
part.Anchored = false
end
end
primary.Anchored = true
primary.CanCollide = false
wait(3)
local part = {Position = Vector3.new(x, 185, z )}
local Tween = tweenService:Create(primary, tweeing, part)
wait(1)
Tween:Play()
Don’t use :SetPrimaryPartCFrame() in production code. It’s less than performant. Same goes for humanoids. The more humanoids in a game, the more lag your game will have.
Instead, it’s better / more efficient to weld the entire model, set its primary part manually and move that. There’s a neat plugin by Ozzypig that does this for you. https://www.roblox.com/library/148570182/Weld-Plugin
If I wrote this free-handed, it would look something like this:
-- Weld the parts to the model's primary part
-- Set the primary part of the model to the primary part (do this manually in studio)
local x = math.random(-192, -166)
local z = math.random(187, 213)
local pos = CFrame.new(x, 200, z)
local dummy = game.StarterGui.plr.Dummy.Models.Start:Clone()
dummy.Parent = workspace.Dummys.Start
dummy.CFrame = CFrame.new(CFrame.new(x, 200, z) * CFrame.Angles(0, math.random(1,360), 0))
dummy.Name = "d1"
wait(3)
local part = {Position = Vector3.new(x, 185, z )}
-- Assuming that these are defined above
local Tween = tweenService:Create(primary, tweeing, part)
wait(1)
Tween:Play()
Hi, thanks for your help! But I had to do it by my own way, or else it doesn’t work. I tween a part of the dummy and a for loop makes the work… My question is, this will lag? The script performance seems ok
local Tween = tweenService:Create(dummy.Falling, tweening, pos1)
Tween:Play()
for i = 0, 55, 1 do
local pos = dummy.Falling.Position
dummy:SetPrimaryPartCFrame(CFrame.new(pos))
wait()
end
This line more specifically is what may cause performance issues. Like I’ve stated before, it’s more practical & more efficient if you weld the model before-hand and move the model based on it’s PrimaryPart.