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
6 years ago
Edited 6 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?

--made by commag


local ChatService = game:GetService("Chat")

Plr = game.Players.LocalPlayer
Char = Plr.Character
TS = game:GetService("TweenService")
repeat wait() until Char
PG = Plr.PlayerGui
G = Instance.new("ScreenGui", PG)
MF = Instance.new("Frame", G)
MF.Size = UDim2.new(0.2,0,0.2,0)
MF.Style = "DropShadow"
MF.Position = UDim2.new(0.8,0,0.8,0)
EVal = Instance.new("StringValue", PG)
EVal.Value = "Unequipped"
T = Instance.new("TextButton", MF)
T.BackgroundTransparency = 1
T.Size = UDim2.new(1,0,1,0)
T.Text = "Death Pillar: " .. EVal.Value
T.TextScaled = true
M = Plr:GetMouse()
Casting = false



----------

M.Button1Down:connect(function()

if Casting == false and EVal.Value == "Equipped" then
Casting = true

ChatService:Chat(Char, "I will cleanse this world...", "Green")
wait(2)
ChatService:Chat(Char, "With The Pillar Of Death!", "Green")


Pillar = Instance.new("Part")
Pillar.Shape = "Cylinder"
Pillar.Size = Vector3.new(0.1,500,0.1)
Pillar.Rotation = Vector3.new(0,90,0)
Pillar.CFrame = CFrame.new(M.Hit.p)
Pillar.TopSurface = "Smooth"
Pillar.BottomSurface = "Smooth"
Pillar.BrickColor = BrickColor.new("Really black")
Pillar.Transparency = 0.4
Pillar.Material = "Neon"
Pillar.Anchored = true
Pillar.CanCollide = false
wait()
Pillar.Parent = workspace


local TIO = TweenInfo.new(
3,
Enum.EasingStyle.Linear,
Enum.EasingDirection.Out,
1,
true,
2
)

local Prop = {
Size = Vector3.new(35,500,35)
}

Pillar.Touched:connect(function(H)
if game.Players:GetPlayerFromCharacter(H.Parent) and H.Parent.Name ~= LS.Name then
H.Parent:BreakJoints()

end

end)

local Tween = TS:Create(Pillar, TIO, Prop)
Tween:Play()
Pillar:Destroy() 
wait()

Casting = false


end
end)

T.MouseButton1Click:connect(function()
if EVal.Value == "Unequipped" and Casting == false then
EVal.Value = "Equipped"
elseif EVal.Value == "Equipped" and Casting == false then 
EVal.Value = "Unequipped"
end
end)

while wait() do
T.Text = "Death Pillar: " .. EVal.Value
end
0
which line has the problem? Resplendid 3 — 6y
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 — 6y

3 answers

Log in to vote
0
Answered by
Azarth 3141 Moderation Voter Community Moderator
6 years ago
Edited 6 years ago
-- Make your variables local unless you need them to be global. Local
-- variables run faster than global variables.

-- Be more descriptive when naming your variables. Things get confusing fast.
local ChatService = game:GetService("Chat")
local Plr = game.Players.LocalPlayer
-- Get Character or wait for it
local Char = Plr.Character or Plr.CharacterAdded:wait()
local TweenService = game:GetService("TweenService")
-- WaitForChild() on children
local PlayerGui = Plr:WaitForChild("PlayerGui")
local ScreenGui = Instance.new("ScreenGui")
local MainFrame = Instance.new("Frame", ScreenGui)
-- U'D'im2.new()
MainFrame.Size = UDim2.new(0.2,0,0.2,0)
-- FrameStyle?
-- MainFrame.FrameStyle = "DropShadow"
MainFrame.Position = UDim2.new(0.8,0,0.8,0)
local EVal = Instance.new("StringValue", PlayerGui)
-- Make value a string, though I don't see why you need it. 
-- If it's because something else changes it, uncomment this
-- and below in the Button1Down event
EVal.Value = 'Equipped'
local TextButton = Instance.new("TextButton", MainFrame)
TextButton.BackgroundTransparency = 1
TextButton.Size = UDim2.new(1,0,1,0)
TextButton.Text = "Death Pillar: " .. EVal.Value

-- Parent after you're done editing properties
ScreenGui.Parent = PlayerGui

local player_mouse = Plr:GetMouse()
local Casting = false



----------

-- Create now, clone when you need it.  
local Pillar = Instance.new("Part")
Pillar.Shape = "Cylinder"
Pillar.Size = Vector3.new(0.1,500,0.1)
Pillar.Rotation = Vector3.new(0,90,0)
Pillar.TopSurface = "Smooth"
Pillar.BottomSurface = "Smooth"
Pillar.BrickColor = BrickColor.new("Really black")
Pillar.Transparency = 0.4
Pillar.Material = "Neon"
Pillar.Anchored = true
Pillar.CanCollide = false

-- Use 'C'onnect
player_mouse.Button1Down:Connect(function()
    if Casting == false then--and EVal.Value == "Equipped" then
        Casting = true

        ChatService:Chat(Char, "I will cleanse this world...", "Green")
        wait(2)
        ChatService:Chat(Char, "With The Pillar Of Death!", "Green")

        local pillar_clone = Pillar:Clone()
        pillar_clone.CFrame = CFrame.new(player_mouse.Hit.p)
        pillar_clone.Parent = workspace


        -- EasingDirection misspelled
        local TIO = TweenInfo.new(3,Enum.EasingStyle.Linear,Enum.EasingDirection.Out,1,true,2)

        local Prop = {Size = Vector3.new(35,500,35)}

        pillar_clone.Touched:Connect(function(hit)
            -- Always prepare for an error, else your script breaks. 
            if hit and hit.Parent then 
                local player = game.Players:GetPlayerFromCharacter(hit.Parent)
                if player then 
                    local victim_char = player.Character
                    if victim_char then 
                        -- Always prepare for an error, else your script breaks. 
                        local this_hum = victim_char:findFirstChild("Humanoid")
                        if this_hum and this_hum.Health > 0 then 
                            player.Character:BreakJoints()
                        end
                    end
                end
            end
        end)

        local Tween = TweenService:Create(pillar_clone, TIO, Prop)
        Tween:Play()
        -- Tween doesn't yield, so destroy is happening right away
        -- Use something like what @thebootsie123 suggested. 
        Tween.Completed:Connect(function()
            pillar_clone:Destroy()
        end)
        wait(3) -- wait total tween time

        Casting = false
    end
end)
Ad
Log in to vote
1
Answered by 6 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.

Tween.Completed:connect(function()
    Pillar:Destroy()
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.

Log in to vote
-1
Answered by 6 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:

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

Answer this question