Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Error message "You can only tween objects in workspace" but I set the parent to workspace. Any help?

Asked by
commag 228 Moderation Voter
7 years ago
Edited 7 years ago

I was making a death Pillar script and it has no errors in the output, but in the client log, it says "can only tween objects in Workspace". Any ideas on how to fix?

01--made by commag
02 
03 
04local ChatService = game:GetService("Chat")
05 
06Plr = game.Players.LocalPlayer
07Char = Plr.Character
08TS = game:GetService("TweenService")
09repeat wait() until Char
10PG = Plr.PlayerGui
11G = Instance.new("ScreenGui", PG)
12MF = Instance.new("Frame", G)
13MF.Size = UDim2.new(0.2,0,0.2,0)
14MF.Style = "DropShadow"
15MF.Position = UDim2.new(0.8,0,0.8,0)
View all 98 lines...
0
which line has the problem? Resplendid 3 — 7y
0
There are no errors in the script output, however in the client log, it says "Can only tween objects in the workspace" commag 228 — 7y

3 answers

Log in to vote
0
Answered by
Azarth 3141 Moderation Voter Community Moderator
7 years ago
Edited 7 years ago
01-- Make your variables local unless you need them to be global. Local
02-- variables run faster than global variables.
03 
04-- Be more descriptive when naming your variables. Things get confusing fast.
05local ChatService = game:GetService("Chat")
06local Plr = game.Players.LocalPlayer
07-- Get Character or wait for it
08local Char = Plr.Character or Plr.CharacterAdded:wait()
09local TweenService = game:GetService("TweenService")
10-- WaitForChild() on children
11local PlayerGui = Plr:WaitForChild("PlayerGui")
12local ScreenGui = Instance.new("ScreenGui")
13local MainFrame = Instance.new("Frame", ScreenGui)
14-- U'D'im2.new()
15MainFrame.Size = UDim2.new(0.2,0,0.2,0)
View all 99 lines...
Ad
Log in to vote
1
Answered by 7 years ago

Alright. So after a little figuring out and something found out by Azarth, what was happening was that the Pillar was getting created and then instantly destroyed since Tween:Play() doesn't yield the script. The fix this problem add this bit of code.

1Tween.Completed:connect(function()
2    Pillar:Destroy()
3end)

What this does is it uses the Tween event called completed. Once the tween is done playing it will run the completed event and then run the function. In this case, the function destroy's the pillar.

Log in to vote
-1
Answered by 7 years ago

At Line 48, Change it to "Pillar.Parent = game.Workspace"

That is because you are not defining Workspace clearly, you said "workspace" the script doesn't know what that is unless you made a variable like:

1local workspace = game.Workspace
0
No, I already did it. Roblox provides the shortcut workspace anyway commag 228 — 7y

Answer this question