I have been working on a script that will move the text up for a few seconds, then move it back down. However, I got an error that says " Can only tween objects in the workspace " , even though I am using TweenPosition.
local textfunction = {}
local startergui = script.Parent
local text = script.Text.StatusText
local clone = text:Clone()
local value = script.Value.Value
function textfunction.movetext()
clone.Text = value
clone.TextTransparency = 0
clone:TweenPosition(
UDim2.new(0.25, 0,0.75, 0),
Enum.EasingDirection.Out,
Enum.EasingStyle.Quad,
2,
false
)
wait(1)
clone:TweenPosition(
UDim2.new(0.25, 0,1, 0),
Enum.EasingDirection.In,
Enum.EasingStyle.Quad,
2,
false
)
clone:Destroy()
end
return textfunction
My door script (local script inside starter player script)
local tween = game:GetService("TweenService")
for _,door in pairs(game.Workspace:GetDescendants()) do
if door:IsA'Model' then
if door.Name == "Door" then
local prompt = door.Base.ProximityPrompt
local locked = door.Locked
local hinge = prompt.Parent.Parent.Doorframe.Hinge
local openandclose = script["Open/Close"]
local locksound = script.Locked
local player = game.Players.LocalPlayer
local textscript = player.PlayerGui:WaitForChild("Text Script")
local value = textscript.Value.Value
local goalOpen = {}
goalOpen.CFrame = hinge.CFrame * CFrame.Angles(0, math.rad(45), 0)
local goalClose = {}
goalClose.CFrame = hinge.CFrame * CFrame.Angles(0, 0, 0)
local Info = TweenInfo.new(1)
local Open = tween:Create(hinge, Info, goalOpen)
local Close = tween:Create(hinge, Info, goalClose)
if locked.Value == true then
prompt.HoldDuration = 0
end
prompt.Triggered:Connect(function()
if locked.Value == true then
if prompt.ActionText ~= "Unlock" then
locksound:Play()
value = "The door is locked!"
local textfunction = require(textscript)
textfunction.movetext()
elseif prompt.ActionText == "Unlock" then
locked.Value = false
Open:Play()
openandclose:Play()
prompt.ActionText = "Close"
prompt.HoldDuration = 1
prompt.Enabled = false
wait(1)
prompt.Enabled = true
end
else
if prompt.ActionText == "Close" then
Close:Play()
openandclose:Play()
prompt.ActionText = "Open"
prompt.Enabled = false
wait(1)
prompt.Enabled = true
else
Open:Play()
openandclose:Play()
prompt.ActionText = "Close"
prompt.Enabled = false
wait(1)
prompt.Enabled = true
end
end
end)
end
end
end
And my tool script (A normal script in workspace)
for _,item in pairs(script.Parent:GetDescendants()) do
if item:IsA'Model' then
local ToolName = item.Name
local Storage = game.ServerStorage
local Part = item.Handle
local prompt = item.invis.ProximityPrompt
prompt.Triggered:connect(function(player)
print("Tool prompt is being activated")
prompt.Enabled = false
if player and player.Character then
local Backpack = player:WaitForChild("Backpack")
local textscript = player.PlayerGui:WaitForChild("Text Script")
local value = textscript.Value.Value
for i = 1, #ToolName do
local Tool = Storage:FindFirstChild(ToolName)
if Tool then
if not Backpack:FindFirstChild(ToolName) and not player.Character:FindFirstChild(ToolName) then
Tool:clone().Parent = Backpack
print("Tool is cloned!")
else
print("Tool did not clone")
value = "You already have this item!"
local textfunction = require(textscript)
textfunction.movetext()
end
end
end
end
wait(1)
prompt.Enabled = true
end)
end
end
also I donât even know why I set a variable for startergui since I never use it, and itâs useless.
The error is rather deceiving; it would appear as if your âStatusTextâ TextLabel isnât located inside of a ScreenGui, thus signaling the warning.
Youâre destroying the Clone the moment you call TweenPosition, which is not a yielding function. You need to wait(2) for the tween to finish. TweenPosition() does not yield code, you must yield the code yourself.
Sorry for the late reply but itâs because youâre parenting it to a gui thatâs under a script (not under a PlayerGui component, therefore not in a GUIâs âworkspaceâ)
Parent the Clone to a GUI thatâs actually under a PlayerGui, itâll fix your issue.
Maybe try using TweenService on a GUI. It acts similarly to TweenPosition, but it has more feature. Such as âCompletedâ event, which you can wait for the tween to finish tweening, and delete the clone.
I used TweenService for my XP manager gui, and it worked pretty well.
I hope this helps with your situation. If something is not working, let me know!