Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Keyboard script help?

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

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)

1 comment

0

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

This discussion is preserved as it was. New answers, comments, and votes are closed.