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

Keyboard script help?

Asked by
JJ_B 250 Moderation Voter
9 years ago

I made a keyboard-like model and I'm trying to make it so when you click a key it goes down for 0.2 seconds and then back up, like a keyboard would. The script I made doesn't work, and the output tells me " Workspace.Console.Keys.Union.Script:4: bad argument #2 to '?' (Vector3 expected, got userdata)"

pos = script.Parent.CFrame

function click()
    pos = pos + CFrame.new(0, -0.2, 0)
    wait(0.2)
    pos = pos + CFrame.new(0, 0.2, 0)
end

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

Somebody please help?

1 answer

Log in to vote
0
Answered by
xPolarium 1388 Moderation Voter
9 years ago

You're changing the CFrame of the part with Vector3.new(). Change it to CFrame.new()

You would use Vector3 to change sizes of the object. Explained here

CFrame is more for changing positions of the object. Explained here

pos = script.Parent.CFrame

function click()
    pos = pos + CFrame.new(0, -0.2, 0)
    wait(0.2)
    pos = pos + CFrame.new(0, 0.2, 0)
end

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

0
I did this, and the output said " Workspace.Console.Keys.Union.Script:4: bad argument #2 to '?' (Vector3 expected, got userdata)" JJ_B 250 — 9y
Ad

Answer this question