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?
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)