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

What did I do wrong here for ClickDetector and all?

Asked by 5 years ago

What I am doing is making a remote and it has Up,Down,Left, and Right. What I am trying to do is click it. It worked when I just did it with the up key, but when trying adding the others in, it didn't even work. It didn't move to the position for 0.05 seconds and back up. Hope you understand what I am trying to do here and asking here. Thank you!

up = script.Parent.Up
down = script.Parent.Down
left = script.Parent.Left
right = script.Parent.Right
upOn = false
downOn = false
leftOn = false
rightOn = false

function onClicked()
    if not upOn then
        upOn = true
    up.CFrame = up.CFrame+Vector3.new(0,-0.09,0)
    wait(0.05)
    up.CFrame = up.CFrame+Vector3.new(0,0.09,0)
            upOn = false
end

   else if not downOn then
        downOn = true
    down.CFrame = down.CFrame+Vector3.new(0,-0.09,0) 
    wait(0.05)
    down.CFrame = down.CFrame+Vector3.new(0,0.09,0)
            downOn = false
end

    else if not leftOn then
        leftOn = true
    left.CFrame = left.CFrame+Vector3.new(0,-0.09,0) 
    wait(0.05)
    left.CFrame = left.CFrame+Vector3.new(0,0.09,0)
            leftOn = false
end

   else if not rightOn then
        rightOn = true
    right.CFrame = right.CFrame+Vector3.new(0,-0.09,0) 
    wait(0.05)
    right.CFrame = right.CFrame+Vector3.new(0,0.09,0)
            rightOn = false
        end

script.Parent.ClickDetector.MouseClick:connect(onClicked)

1
else if... use elseif greatneil80 2647 — 5y
1
Yeah, use elseif with no space AswormeDorijan111 531 — 5y
0
I did that, but that didn't work. RobotChitti 167 — 5y
1
First of all, keep in mind that *I cannot see your code*. This is the code that you made and I am merely fixing the bugs which you had. Zafirua 1348 — 5y
View all comments (4 more)
1
Secondly, the error is exactly as it means. You one, either don't have a click detector in the model or, two, you did not reference the model properly. I don't know what line 53 is so I cannot help you unless you post me a picture of your stuff and your full code.  Zafirua 1348 — 5y
1
Do accept the answer because I did help you in this context. And also post your pictures so I can help you more. Zafirua 1348 — 5y
0
I accepted your answer. Should I re-ask it then? RobotChitti 167 — 5y
0
Along with the picture? RobotChitti 167 — 5y

1 answer

Log in to vote
1
Answered by
Zafirua 1348 Badge of Merit Moderation Voter
5 years ago
Edited 5 years ago

As pointed out by others, you cannot use elseif with spaces.

You also should not be using deprecated events. Switch from connect() to Connect(). You should also be using local on most of your codes.

A fix to your code.

-- [Declaration Section]
local Up               = script.Parent.Up;
local Down             = script.Parent.Down;
local Left             = script.Parent.Left;
local Right            = script.Parent.Right;

--\\ Variables 
local UpOn             = false;
local DownOn           = false;
local LeftOn           = false;
local RightOn          = false;

-- [Processing Section]
local function On_Clicked ()
    if not UpOn then 
        UpOn = true;

        up.CFrame = up.CFrame + Vector3.new(0, -0.09 ,0);
        wait()
        up.CFrame = up.CFrame + Vector3.new(0, 0.09 ,0);

        UpOn = false;
    elseif not DownOn then
        DownOn = true;

        Down.CFrame = Down.CFrame + Vector3.new(0, -0.09 ,0);
        wait()
        Down.CFrame = Down.CFrame + Vector3.new(0, 0.09 ,0);

        DownOn = false;
    elseif not LeftOn then 
        LeftOn = true;

        Left.CFrame = Left.CFrame + Vector3.new(0, -0.09 ,0);
        wait()
        Left.CFrame = Left.CFrame + Vector3.new(0, 0.09 ,0);

        LeftOn = false;
    elseif not RightOn then 
        RightOn = true;

        Right.CFrame = Right.CFrame + Vector3.new(0, -0.09 ,0);
        wait()
        Right.CFrame = Right.CFrame + Vector3.new(0, 0.09 ,0);

        RightOn = false;
    else 
        return;
    end;
end;

-- [Connecting Section]
script.Parent.ClickDetector.MouseClick:Connect(On_Clicked);
0
I tested the script out, but it didn't function it. I clicked each parts and none of them went down. I checked for any errors, but there aren't any. RobotChitti 167 — 5y
0
Nevermind. This is what the output said when I put the script in: 22:39:06.408 - ClickDetector is not a valid member of Model 22:39:06.409 - Stack Begin 22:39:06.411 - Script 'Workspace.RemoteControl.Script', Line 53 22:39:06.412 - Stack End RobotChitti 167 — 5y
Ad

Answer this question