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.
Firstly, let me address the things that you may need to know, or is causing your script to break.
[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.
[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.
[Line 5] Use HumanoidRootPart rather than LowerTorso. It will work for both R6 and R15.
[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!
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
try adding pard.Parent = workspace