Hey there! I am having a problem with tweening my pet, I am new to tweening parts so, bear with me.
My code:
local TweenService = game:GetService("TweenService")
local Object = script.Parent
function onPlayerAdded(player)
local function onCharacterAdded(character)
while true do
wait(1)
local TweenService = game:GetService("TweenService")
local tweenInfo = TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, 0, false, 0)
local tween = TweenService:Create(Object.Head, tweenInfo, character.Head.NeckRigAttachment)
tween:Play()
end
end
player.CharacterAdded:Connect(onCharacterAdded)
end
game.Players.PlayerAdded:Connect(onPlayerAdded)
I am getting this error
09:28:47.900 Unable to cast to Dictionary - Server - Script:12
09:28:47.900 Stack Begin - Studio
09:28:47.900 Script 'Workspace.Regular Eggs.Common Egg.Dog.Script', Line 12 - function onCharacterAdded - Studio - Script:12
09:28:47.900 Stack End - Studio
The "unable to cast to dictionary is coming from this line
local tween = TweenService:Create(Object.Head, tweenInfo, character.Head.NeckRigAttachment)
I know I am doing something wrong, I just don’t know what!
There is no need to apologize.
The error you are getting right now is telling you that you have failed to create the CFrame.
Here is the problem.
You can use {CFrame = character.NeckRigAttachment.CFrame}.
While you are using CFrame.new() you can’t pass a CFrame as an argument.
local TweenService = game:GetService("TweenService")
local Object = script.Parent
function onPlayerAdded(player)
local function onCharacterAdded(character)
wait(5)
script.Parent.Head.AlignOrientation.Attachment1 = character.Head.NeckRigAttachment
while true do
wait()
local tweenInfo = TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, 0, false, 0)
local tween = TweenService:Create(Object.Head, tweenInfo, {CFrame = character.Head.NeckRigAttachment.CFrame})
tween:Play()
end
end
player.CharacterAdded:Connect(onCharacterAdded)
end
game.Players.PlayerAdded:Connect(onPlayerAdded)
robloxapp-20210110-1652071_Trim.wmv (2.2 MB)
It goes to the middle of the world, how and why does that happen?
The parts around it also don’t stick to the original head, even though they are welded to it…
Thanks, it worked! I have one question though, how would I make so that there is an off set from the players head but only on one side relative to the player, because if I tried to do a vector3 it would only offset on the world axis? Or should I just make an attachment stick out on the side of the player’s head?
finalOffsetCFrame = targetCFrame * targetOffsetCFrame
finalOffsetCFrame would be the resulting CFrame you asked about.
targetCFrame would be the starting CFrame you want offset from.
targetOffsetCFrame would be the offset you want to apply.
In your case, if you want an offset that is 5 studs right, 5 studs up, and 5 studs forward from the head you would do