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

What's wrong with this script?!

Asked by 9 years ago

What I'm trying to do is make a part move when it is clicked, Like an elevator, but with this script It will not work, please help me solve the problem with it.


local.Part = script.Parent

function OnClick() Part.Position = (2,2,2) wait(0.5) Part.Position = (2,3,2) wait(0.5) Part.Position = (2,4,2) wait(0.5) Part.Position = (2,5,2) end

2 answers

Log in to vote
2
Answered by 9 years ago

To fix your current script, try the script below:

local Part = script.Parent -- There is no `.` between `local` and `Part` .
function OnClick() 
    Part.Position = (2,2,2) 
        wait(0.5) 
    Part.Position = (2,3,2) 
        wait(0.5) 
    Part.Position = (2,4,2) 
        wait(0.5) 
    Part.Position = (2,5,2) 
end

script.Parent.ClickDetector.MouseClick:connect(onClick) -- You must have a line dedicated to firing the event. Assuming the part contains a ClickDetector, this line should work.

If my answer helped you, accept and upvote it. If not, please tell me the error message in the comments below.

Ad
Log in to vote
0
Answered by
saenae 318 Moderation Voter
9 years ago

There are a couple things that are a tad off with this code, but easily fixable. First off, I'm assuming that you'd meant to make your 'Part' variable local, not name it 'local.Part.' To do that, all we do is replace the dot with a space.

local Part = script.Parent

From there, we need an actual event that will work with clicking your part, which will likely need a ClickDetector.

ClickD = Instance.new("ClickDetector", Part) -- Creating the clickdetector and putting it in your part.
ClickD.MouseClick:connect(function() -- the event used when someone clicks on your brick.
--Code
end)

Also, for movement, I think you'd find using a loop to be more efficient, and much easier than typing out exactly what you want the code to do.

for i = 1, 4 do
    Part.Position = Vector3.new(2, 1+i, 2)
    wait(0.5)
end

To wrap it up;

local Part = script.Parent
ClickD = Instance.new("ClickDetector", Part)
ClickD.MouseClick:connect(function()
    for i = 1, 4 do
        Part.Position = Vector3.new(2, 1+i, 2)
        wait(0.5)
    end
end

Hope this helps ^^

0
Is this right? local Part = script.Parent ClickD = Instance.new("ClickDetector", Part) ClickD.MouseClick:connect(function)() for (i = 1, 4) do Part.Position = Vector3.new(2, 1+i, 2) wait(0.5) end end Lando13370 0 — 9y
0
That should work, yeah. :) Just make sure to put a bracket beside your last end,. saenae 318 — 9y

Answer this question