Help with Tween

So I am tweening a model to follow a player continuously but it says that it is Unable to cast string to dictionary.

Original Code
local Flag = script.Parent
local Action = "Follow"
local Plr
local Char
local HumRootPart

local UserInputService = game:GetService("UserInputService")
local TweenService = game:GetService("TweenService")
local TweenInfo = {
	1,
	Enum.EasingStyle.Linear,
	Enum.EasingDirection.Out,
	0,
	false,
	0
}
local tween

game.Players.PlayerAdded:Connect(function(plr)
	Plr = plr
	Char = Plr.Character or Plr.CharacterAdded:Wait()
	HumRootPart = Char:WaitForChild("HumanoidRootPart")
	print(HumRootPart)
end)

UserInputService.InputBegan:Connect(function(key)
	if key.KeyCode == Enum.KeyCode.R then
		Action = "Charge"
	elseif key.KeyCode == Enum.KeyCode.G then
		Action = "Hold"
	elseif key.KeyCode == Enum.KeyCode.F then
		Action = "Follow"
	end
end)

while Action == "Follow" do
	wait()
	print(HumRootPart)
	if HumRootPart ~= nil then
		tween = TweenService:Create(Flag, TweenInfo, {HumRootPart.Position})
		tween:Play()
	end
end

Edited code;

local Flag = script.Parent.Parent.PrimaryPart
local Action = "Follow"
local Plr
local Char
local HumRootPart

local UserInputService = game:GetService("UserInputService")
local TweenService = game:GetService("TweenService")
local TweenInfo = TweenInfo.new(
	1,
	Enum.EasingStyle.Linear,
	Enum.EasingDirection.Out,
	0,
	false,
	0
)
local tween

game.Players.PlayerAdded:Connect(function(plr)
	Plr = plr
	Char = Plr.Character or Plr.CharacterAdded:Wait()
	HumRootPart = Char:WaitForChild("HumanoidRootPart")
end)

UserInputService.InputBegan:Connect(function(key)
	if key.KeyCode == Enum.KeyCode.R then
		Action = "Charge"
	elseif key.KeyCode == Enum.KeyCode.G then
		Action = "Hold"
	elseif key.KeyCode == Enum.KeyCode.F then
		Action = "Follow"
	end
end)

while Action == "Follow" do
	wait()
	if HumRootPart ~= nil then
		tween = TweenService:Create(Flag, TweenInfo, {Position = HumRootPart.Position, Orientation = HumRootPart.Orientation})
		tween:Play()
	end
end

You have to do Position = HumRootPart.Position

2 Likes

Along with what Beelzebuub said, you also did your TweenInfo wrong. You have to do it like this

local TweenInfo = TweenInfo.new(
	1,
	Enum.EasingStyle.Linear,
	Enum.EasingDirection.Out,
	0,
	false,
	0
)
1 Like

Ok, so it works for one piece of the model nothing else follows the player though and how would I make it change the orientation also.

Edit;
The entire model (each piece) is welded to the flag.

So first off, you will need to set a primary part for the model and weld it together if you haven’t already. And then change local Flag = script.Parent to local flag = PathToModel.PrimaryPart
I just saw your edit. Just make your Flag the primary part, and then you can keep local Flag = script.Parent

And then your tween should look like

tween = TweenService:Create(Flag, TweenInfo, {Position = HumRootPart.Position, Orientation = HumRootPart.Orientation})
1 Like

So I changed what you told me to and still only the flag comes to the player despite each and every part being welded to it. And The orientation is somehow messed up where the flag is sideways.

I fixed the orientation bug by changing my tween to tween = TweenService:Create(Flag, TweenInfo, {Position = HumRootPart.Position, Orientation = HumRootPart.Orientation - Vector3.new(0, -90, -90)}), but still only the flag will come to the player.

Are all the parts in the model unanchored?

No they are all anchored. And when I make a weld constraint it’s grey instead of the usual green. Does this mean anything?

I’m not too familiar with weld constraints, but attempt unanchoring the parts and see what happens

Edit: Your weld constraints are greyed out because they’re already being welded by another part and it just signifies it isn’t necessary.

Unanchoring the parts made the welds turn green, but the rest of the model still doesn’t move.