Unable to change position of a cloned Part

  1. What do you want to achieve?
    I am trying to change the position of a cloned object. This original object is in ReplicatedStorage. The cloned object is moved to a folder in Workspace.
  2. What is the issue?
    Objects are maintaining the position of the original ReplicatedStorage.Target position
  3. What solutions have you tried so far?
    See code below - I have tried searching multiple DevForum posts but I am not see an issue with the code
local radius = 100

while true do 
	wait(5)
	
	local target = game.ReplicatedStorage.Target:Clone()
	
	local angle = math.random(1,360)

	local x = radius * math.cos(angle)
	local z = radius * math.sin(angle)
	
	target.Position = Vector3.new(x, 5, z)

	target.Parent = workspace.Targets -- This is a folder in Workspace
end

The object in ReplicatedStorage is called “Target” and has a position of 0,0,0. On line 14, I try to set the cloned Object ‘target.Position’ to my generated values, nothing happens. The game continues to set the parent to Workspace and maintains the original position found in ReplicatedStorage.
Any help is appreciated.

When running the script - here are a few example X, Z values that are generated:
27.519231863229308 -96.13891968218607
-99.6087835141185 8.836868610400144
54.03023058681398 84.14709848078965

1 Like

Change the position of it after parenting it to workspace.

1 Like

Your code looks good. I even ran it myself and it worked. I would look into if there’s any other code anywhere that’s setting the position of the target.

Also, math.cos/sin take radians, not degrees, so your angle calculation should be: local angle = math.random() * math.pi * 2 (or use math.rad()). But this isn’t regarding it working or not.

1 Like

Swapping the order of target.Position and target.Parent has the same outcome. I’ll check for any other scripts changing the position

Disabled all of the other scripts and it is working, ended up being an issue with a tween I have implemented on the generated parts. Thank you and thank you for the radians comment, it appears to be working correctly now.

---- Specifically my Time Variable in a tween affecting new parts was set to 0, instantaneously moving the part to the destination location.

1 Like

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