Model:MoveTo() Very broken

  1. What do you want to achieve?
    The flag to be teleported on both clients and server to the set spot

  2. What is the issue?
    Teleported itself to random places on BOTH client and server

Server:
image
Client:
image

  1. What solutions have you tried so far?
    No proper articles on how to do this, plus, I can’t fix something like this using a deprecated part of Roblox.
script.Parent.Unequipped:Connect(function()
	local ServerStorageService = game:GetService("ServerStorage")
	
	local FlagTool = script.Parent
	local FlagModel = FlagTool.Flag
	local Player = FlagTool.Parent.Parent
	
	repeat
		task.wait()
	until FlagTool.Parent.Name == "Backpack"
	
	FlagModel.Parent = workspace
	FlagTool.Parent = ServerStorageService.DroppedFlags
	
	FlagModel:MoveTo(Player.Character.Torso.Position + Vector3.new(0,5,0))
	
	for index, object in ipairs(FlagModel:GetDescendants()) do
		if object:IsA("BasePart") then
			object.Anchored = false
			object.CanCollide = false
		end
	end
	
	FlagModel.Detection.Touched:Connect(function(otherPart)
		
		local CanContinue = true
		
		for index, object in ipairs(FlagModel:GetDescendants()) do
			if object == otherPart then 
				CanContinue = false
			end
		end
		if CanContinue == true then 
			for index, object in ipairs(FlagModel:GetDescendants()) do
				if object:IsA("BasePart") then
					object.Anchored = true
					object.CanCollide = false
				end
			end
		end
		
	end)
end)

Instead of using :MoveTo you can do,

FlagModel.PrimaryPart.Position = Player.Character.Torso.Position + Vector3.new(0,5,0)

Make sure the PrimaryPart is welded to al the parts in the model.

For some reason it doesn’t do this part of the script when it touches terrain. Should I make another thread about this?

	FlagModel.Detection.Touched:Connect(function(otherPart)
		
		local CanContinue = true
		
		for index, object in ipairs(FlagModel:GetDescendants()) do
			if object == otherPart then 
				CanContinue = false
			end
		end
		if CanContinue == true then 
			for index, object in ipairs(FlagModel:GetDescendants()) do
				if object:IsA("BasePart") then
					object.Anchored = true
					object.CanCollide = false
				end
			end
		end
		
	end)

im pretty sure the terrain doesn’t trigger the touched event, but you could make a hitbox for the terrain.
Also I recommend Model:PivotTo()

1 Like

It does, I think the actual issue is it’s not adding the offset. And, I’ve already tried :PivotTo and :MoveTo but both completely bug out.

So i think i’ve figured it out.
When the tool in unequipped you send a remote to the server, and the server runs the following code. Keep in mind that you will need some way to reference the flag, and you’ll probably want to add sanity checks.

local rs = game:GetService("ReplicatedStorage")

local tool = script.Tool --my way of letting the script know what the tool is

rs.DroppedFlag.OnServerEvent:Connect(function(plr)
	local char = plr.Character
	if char then
		tool.Parent = workspace
		tool.Handle:PivotTo(char.HumanoidRootPart.CFrame+Vector3.new(0,5,0))
	end
end)

Sorry for the late reply, I was kinda confused

1 Like

The script is a ServerScript, not a LocalScript.

Oh I didn’t realize, here’s a server-sided version:

local rs = game:GetService("ReplicatedStorage")

local tool = script.Tool --make sure that the script can set a variable to the tool before it is given to a player

tool.Unequipped:Connect(function(p)
	local tp = tool.Parent
	local char = tp
	if tool.Parent:IsA("Backpack") then
		char = tp.Parent.Character
	end
	if char then
		task.wait()
		tool.Parent = workspace
		tool.Handle:PivotTo(char.HumanoidRootPart.CFrame+Vector3.new(10,5,0))
	end
end)

may need to replace the task.wait() with a better method of not changing the parent to workspace while its being set to backpack. Also, if you don’t want the player to be able to unequip the flag at all you could set manual activation only for the tool and hide the backpack, although i would still run this script as well in case of exploiters.