I’m not sure what I did wrong, here, take a look. (Error is “Unable to Cast Value to Object”)
local gameServices = {
tweenService = (game:GetService("TweenService"));
playerService = (game:GetService("Players"))
}
local charVariables = {
humRootPart = (gameServices.playerService.LocalPlayer.Character.HumanoidRootPart)
}
local tweenDefaultSettings = {
defaultInfo = (TweenInfo.new(4, Enum.EasingStyle.Quad, Enum.EasingDirection.In, 0, false, 0))
}
local function returnCFrame(Variable)
return (Variable.CFrame);
end
local function tweenObject(Object, Info, Properties)
-->> Error comes from under here.
local temporaryTween = (gameServices.tweenService:Create(Object, Info, Properties));
temporaryTween:Play()
return (temporaryTween)
end
local function tweenTest()
local temporaryCFrame = (CFrame.new(357.203949, 48.4761887, -509.941467, -0.991344094, 2.28747723e-08, -0.131291226, 1.06303597e-08, 1, 9.39623703e-08, 0.131291226, 9.1753364e-08, -0.991344094));
tweenObject(charVariables, tweenDefaultSettings.defaultInfo, {CFrame = temporaryCFrame});
print("Ran the script.")
end
tweenTest()
Please consider taking into consideration scripting in an adequate way.
local tweenService = (game:GetService("TweenService"));
local playerService = (game:GetService("Players"))
local LocalPlayer = playerService.LocalPlayer
local goal = CFrame.new(357.203949, 48.4761887, -509.941467, -0.991344094, 2.28747723e-08, -0.131291226, 1.06303597e-08, 1, 9.39623703e-08, 0.131291226, 9.1753364e-08, -0.991344094)
local tweenDefaultSettings = {
defaultInfo = (TweenInfo.new(4, Enum.EasingStyle.Quad, Enum.EasingDirection.In, 0, false, 0))
}
--[[
have you heard about directly getting the value from the "Variable"?
local function returnCFrame(Variable)
return (Variable.CFrame);
end]]
local function tweenObject(Object, Info, Properties)
local temporaryTween = (tweenService:Create(Object, Info, Properties));
temporaryTween:Play()
return (temporaryTween)
end
local function tweenTest()
tweenObject(LocalPlayer.Character:WaitForChild'HumanoidRootPart', tweenDefaultSettings.defaultInfo, {CFrame = goal});
print("Ran the script.")
end
tweenTest()
I know it’s a bit weird right now, but I’m gonna use the function a lot more than once. I’d like to refrain from using global variables for every CFrame value.
I was refering to his use of useless tables that the garbage collector will have to clean as a direct consequence of his coding ways. “Syntax sugar” makes no difference on the script’s performance.
The function is quite literally filler. I didn’t intend on saying that you have to globalize every CFrame value because I assume some aren’t going to be static. You’re just putting code fluff. print(returnCFrame(workspace.Part)) and print(workspace.Part.CFrame) are the same, with the latter just being more efficient.
It’s not just “unnecessary”, it impacts the code’s speed. As arrogant and clichè as I may sound, it’s good practice to localize things that are used numerous times in your code.