I put this code into a local script in Start Pack
Player = script.Parent.Parent mouse = Player:GetMouse() function onKeyDown(key) key = key:lower() if key == "z" then TestHouse = game.Lighting.House:clone() TestHouse.parent = game.Workspace end end mouse.KeyDown:connect(PressedZ)
Its supposed to detect that I pressed Z and then clone game.lighting.House
But when I press Z the output returns with "attempt to call a nil value" in red.
Any thoughts as to why this doesn't work?
At line 12, the function PressedZ isn't written beforehand in the script. Try replacing that with "mouse.KeyDown:connect(onKeyDown)"
Also, I think the nil value is from line 8, where you try to set the parent of the house to Workspace. You put in "parent", when the property is named Parent
. (CaSE SEnSITiVe!)
Player = game:GetService('Players').LocalPlayer mouse = Player:GetMouse() function onKeyDown(key) key = key:lower() if key == "z" then TestHouse = game.Lighting.House:clone() TestHouse.Parent = game.Workspace end end mouse.KeyDown:connect(onKeyDown)
(Side note, KeyDown
is now deprecated. UserInputService
is a better choice.)
Don't forget to accept my answer if this helps!