My model won´t change position

Hello, im making a game inspired by Super Bomb Survival, as of right now im making a explosion module so i can make the player go boom.

But im having a problem, since my explosion is a model i have to use model:MoveTo(), but when i do it, it just stays at the original position of the model, not the position i want, i dont know if model:PivotTo() will work since im passing a Vector3 value not a CFrame and i don´t want to pass a CFrame value becouse of varius reasons.

This is how my model is organized:
Hithisismyimage
The meshes are just the ball model, but the PrimaryPart is the part that emmits the sound and the primary part of the model; I tried moving PrimaryPart since is the primary part of my model but it gives the same results.

This is the part of the code where im having problems:

function Explosion:Explode()
	
	task.spawn(function()
		local explosionClone = self.Model:Clone()
		explosionClone:MoveTo(self.Position) --Wont work :(
		explosionClone.Parent = workspace

		local soundClone = sound:Clone()
		soundClone.Parent = explosionClone:FindFirstChild("PrimaryPart")
		soundClone:Play()

		task.delay(2, function()
			explosionClone:Destroy()
		end)
	end)
end

This is a script which calls the creation of a explosion:
myExplosion

This is the result, as you can see, the model is not in the position i want it to be.

3 Likes

Could you show the Explosion.New function in your module? The issue may be due to the initial declaration of the position variable

Sure, here you go

local Explosion = {}
Explosion.__index = Explosion

function Explosion.New(Position : Vector3, Radius : number, MaxDamage : number, MinDamage : number, Model : Model)
	local self = setmetatable({}, Explosion)
	self.Position = Position
	self.Radius = Radius
	self.MaxDamage = MaxDamage
	self.MinDamage = MinDamage
	self.Model = Model
	
	return self
end
1 Like

I’m pretty sure that MoveTo() is only moving the PrimaryPart and leaving the meshes behind, try this:

  1. Make sure that meshes are unanchored
  2. Join them to PrimaryPart using WeldConstraints
    (This should work for MoveTo)

Also, you can use PivotTo() if you put it like this:

explosionClone:PivotTo(CFrame.new(self.Position))
1 Like

:MoveTo() I’ve heard in some places that it’s deprecated and often doesn’t work and you should switch to :PivotTo(). As for :PivotTo() it only takes a CFrame and nothing else. To implement your fix to Explosion:Explode(), you use a CFrame constructor with a Vector3.

function Explosion:Explode()
	
	task.spawn(function()
		local explosionClone = self.Model:Clone()
		explosionClone:PivotTo(CFrame.new(self.Position)) -- Try this fix :)
		explosionClone.Parent = workspace

		local soundClone = sound:Clone()
		soundClone.Parent = explosionClone:FindFirstChild("PrimaryPart")
		soundClone:Play()

		task.delay(2, function()
			explosionClone:Destroy()
		end)
	end)
end

The model should move to the desired place but without orientation because of Vector3.Position represents pure position data and no orientation if that’s your goal.

3 Likes

You can also use Debris Service and add your explosionClone to a deletion queue:

Instead of:

task.delay(2, function()
	explosionClone:Destroy()
end)

Try:

--At the top of the script (or anywhere before your function)
local Debris = game:GetService("Debris")

--Now in your function
Debris:AddItem(explosionClone, 2) --Deletes the explosionClone after 2 seconds
1 Like

It works now! Tysm!

Also thanks for this, i forgot Debris existed lol.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.