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

why does my script that makes a part's position increase until it's at my position not work?

Asked by 3 years ago
workspace:WaitForChild("defaultkid99")
repeat 
    script.Parent.Position = script.Parent.Position+Vector3.new(math.random,math.random,math.random)
until script.Parent.Position = defaultkid99.Torso.Position

why do i get an error? what does it mean error while parsing expression expected <eof> got =

2 answers

Log in to vote
0
Answered by 3 years ago

try using local default = workspace:WaitForChild("defaultkid99")

0
here is my new code local default = workspace:WaitForChild("defaultkid99") local pos = script.Parent.Position local defpos = default.Torso.Position repeat script.Parent.Position = script.Parent.Position+Vector3.new(math.random,math.random,math.random) until pos = defpos defaultkid99 4 — 3y
0
put it in a code block please its hard to understand unformatted catsalt29 57 — 3y
0
hmm i dont kmow catsalt29 57 — 3y
0
~local default = workspace:WaitForChild("defaultkid99") local pos = script.Parent.Position local defpos = default.Torso.Position repeat script.Parent.Position = script.Parent.Position+Vector3.new(math.random,math.random,math.random) until pos = defpos~ defaultkid99 4 — 3y
0
~~~~~~~~~~~~~~~~~ local default = workspace:WaitForChild("defaultkid99") local pos = script.Parent.Position local defpos = default.Torso.Position repeat script.Parent.Position = script.Parent.Position+Vector3.new(math.random,math.random,math.random) until pos = defpos ~~~~~~~~~~~~~~~~~ defaultkid99 4 — 3y
Ad
Log in to vote
0
Answered by 3 years ago

Ok, there's a lot of things wrong with your script, so I'll go through them one by one and then give you a script that works

workspace:WaitForChild("defaultkid99")

You didn't define a variable here. This line of code is effectively meaningless.

repeat 
    script.Parent.Position = script.Parent.Position+Vector3.new(math.random,math.random,math.random)

math.random requires parameters - those being a smaller number and a greater number, and it'll pick a number between those two numbers. Proper usage would be something along the lines of math.random(1,10).

until script.Parent.Position = defaultkid99.Torso.Position

When comparing two values, you have to use two equals signs to signify 'is this thing equal to that other thing'. If you use one equal sign, you're telling the script to set the first value to the second, which wouldn't work in this case. This is also the reason for your error message. Not to mention you use defaultkid99 here as if you defined a variable, which you didn't.

So all together, here's a fixed up script for you.

local defaultkid = workspace:WaitForChild("defaultkid99")
repeat 
    local increasevalue = math.random(1,10) -- Change these 2 numbers as you see fit. The resulting variable will be a number equal to or between those two numbers.
    script.Parent.Position = script.Parent.Position+Vector3.new(increasevalue, increasevalue, increasevalue)
    wait(1) -- The script would stop working without this wait here
until script.Parent.Position == defaultkid.Torso.Position

Now this would work on paper, but here's some notes. Whatever script.Parent is will be moving along all 3 axis - X,Y,Z positively. That means it'll always be moving forward a little, left a little, and up a little. If this is not your intention, you can play around with this line: script.Parent.Position = script.Parent.Position+Vector3.new(increasevalue, increasevalue, increasevalue) by changing one or two of the three increasevalue variables to 0 until it moves in a way you see fit.

Answer this question