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

I'm having trouble with a looping Instance new script; syntax correct, I believe a logic error?

Asked by 6 years ago
function levit ()
    while true do
    local pard = Instance.new("Part",workspace)
    pard.Anchored = true
    pard.Position = script.Parent.Parent.LowerTorso.Position - Vector3(0,3,0)
    wait (1)
    pard:Destroy()
    end
end






script.Parent.Equipped:Connect(levit)

I'm a novice and just tinkering to really reinforce what I've been learning; that being said I've attempted a sort of "levitation" script (similar to the path scripts of obby's in the olden days). It is located in a tool in the StarterPack, and it's intended that when the user equips the tool, a loop starts making parts spawn under their feet for a second and then be destroyed. I've been tinkering for quite some while now and the output and script analysis have cleared me of syntax errors but it's still not processing properly. Thank you.

0
Btw try not to use the Instance.new's second argument. "Instance.new("Part",workspace)<---- it's better to set the parent afterwards Radstar1 270 — 6y

3 answers

Log in to vote
1
Answered by
UgOsMiLy 1074 Moderation Voter
6 years ago

Firstly, let me address the things that you may need to know, or is causing your script to break.

  1. [Line 2] As one of the other helpers said, the while true do loop will never end, unless you put "break" in your script. The solution is to set a value every time you [un]equip it. That will make sense soon.

  2. [Line 3] The method of putting the parent inside the instance.new function is deprecated. Put pard.Parent = workspace after setting the default properties. In this case, just before wait(1). The reason they don't want you to do that is because it can create lag. Look at this article for more info. This isn't breaking your script though.

  3. [Line 5] Use HumanoidRootPart rather than LowerTorso. It will work for both R6 and R15.

  4. [Line 5] Vector3 is not a function, it's a table full of functions.Vector3.new is what you're after. That's the function that creates a Vector3. That's one of the reasons your script broke.

Another factor is that the "RequiresHandle" property on your tool must be checked. Look in "properties" under that tool.

And make sure that the script is a Script, not a LocalScript.

Now for the solution.

Put this in a Script inside the Tool.

local equipped = false

function levit()
    equipped = true
    while equipped do -- fix to problem 1
        local pard = Instance.new("Part")
        pard.Anchored = true
        pard.Position = script.Parent.Parent.HumanoidRootPart.Position - Vector3.new(0,3,0) -- fix to problem 3 & 4
        pard.Parent = workspace -- fix to problem 2
        wait (1)
        pard:Destroy()
    end
end

script.Parent.Unequipped:Connect(function()
    equipped = false
end)

script.Parent.Equipped:Connect(levit)

Hope that helped!

Ad
Log in to vote
0
Answered by
xAtom_ik 574 Moderation Voter
6 years ago

Firstly, that while true do loop will never exit even if you unequip the tool. Try connecting the Unequipped event and set a variable to break the loop if it is true (and also set it to false before you break the loop). Furthermore, On line 5 it should be Vector3.new not Vector3

Log in to vote
0
Answered by 6 years ago

try adding pard.Parent = workspace

0
He has the parent set in Instance.new MooMooThalahlah 421 — 6y

Answer this question