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