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 |
04 | local ChatService = game:GetService( "Chat" ) |
05 |
06 | Plr = game.Players.LocalPlayer |
07 | Char = Plr.Character |
08 | TS = game:GetService( "TweenService" ) |
09 | repeat wait() until Char |
10 | PG = Plr.PlayerGui |
11 | G = Instance.new( "ScreenGui" , PG) |
12 | MF = Instance.new( "Frame" , G) |
13 | MF.Size = UDim 2. new( 0.2 , 0 , 0.2 , 0 ) |
14 | MF.Style = "DropShadow" |
15 | MF.Position = UDim 2. new( 0.8 , 0 , 0.8 , 0 ) |
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. |
05 | local ChatService = game:GetService( "Chat" ) |
06 | local Plr = game.Players.LocalPlayer |
07 | -- Get Character or wait for it |
08 | local Char = Plr.Character or Plr.CharacterAdded:wait() |
09 | local TweenService = game:GetService( "TweenService" ) |
10 | -- WaitForChild() on children |
11 | local PlayerGui = Plr:WaitForChild( "PlayerGui" ) |
12 | local ScreenGui = Instance.new( "ScreenGui" ) |
13 | local MainFrame = Instance.new( "Frame" , ScreenGui) |
14 | -- U'D'im2.new() |
15 | MainFrame.Size = UDim 2. new( 0.2 , 0 , 0.2 , 0 ) |
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.
1 | Tween.Completed:connect( function () |
2 | Pillar:Destroy() |
3 | end ) |
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.
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:
1 | local workspace = game.Workspace |