Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Does anyone know why my Model isn't moving to the Position I have set?

game.ReplicatedStorage.RemoteEvents.Chunk1.OnClientEvent:Connect(function()
	game.Workspace.ChunkD:Destroy()
	local chunklist = game.ReplicatedStorage.Chunks
	local options = chunklist:GetChildren()
	local chunk = options[math.random(1, #options)]
	chunk:Clone().Parent = game.Workspace
	local chunkpos = game.Workspace.Chunk4.PrimaryPart.Position + Vector3.new(0,0,45)
	chunk:MoveTo(chunkpos)
end)

I'm not receiving any output. Chunkpos is the position I want it set to by the way.

2 comments

0

I don't actually understand? what's a chunkpos and what's the goal for this script?

0

Chunkpos is the position of a model in Workspace plus the z-value I want to add. The goal for this script is to clone a model and move it to the position of chunkpos.

2 answers

✓ Accepted answer

Because on line 6 you are cloning chunk and parenting it to workspace, the problem with that is that you do not have any refernces of it so it still refers to the old non-cloned chunk on line 5 when moving it, so you are moving the chunk that is not visibile, all you have to do is set new chunk variable to the cloned one:

game.ReplicatedStorage.RemoteEvents.Chunk1.OnClientEvent:Connect(function()
	game.Workspace.ChunkD:Destroy()
	local chunklist = game.ReplicatedStorage.Chunks
	local options = chunklist:GetChildren()
	local chunk = options[math.random(1, #options)]

	-- here
	local newchunk = chunk:Clone()
	local chunkpos = game.Workspace.Chunk4.PrimaryPart.Position + Vector3.new(0,0,45)
	newchunk:MoveTo(chunkpos)
	newchunk.Parent = workspace
end)

Also instead of game.Workspace you can just use workspace.

1 comment

0

Works perfectly. Thank you!

Try this

local model = script.Parent model:MoveTo(Vector3.new(0, 10, 0)) -- move 10 studs up in the y-axis from the origin model:SetPrimaryPartCFrame(CFrame.new(0, 20, 0) * CFrame.Angles(0, math.rad(45), 0)) -- move 20 studs in the y-axis from the origin and rotate 45 degrees in the y-axis

This discussion is preserved as it was. New answers, comments, and votes are closed.