Hey, This is my second attempt on a script i am attempting. I am trying to make a script that allows the player to unanchor a part if a key is pressed and touching a certain block, I have used a normal script and a module script, however the functions don't seem to connect with eachother:

Module Script:

local onKeyPress = {}
function onKeyPress(inputObject, gameProcessedEvent)
	
end
return onKeyPress

Script:

local OnKeyPress = require(game.Workspace.ModuleScript)
function onTouch(hit)
if **onKeyPress**().KeyCode == Enum.KeyCode.F and hit.game.workspace.Name == "DoorKick" then
		script.Parent.Parent.DoorKick.Anchored = false
		script.Parent.Parent.DoorKick.CanCollide = false
	end
   end
script.Parent.Touched:connect(onTouch)
game:GetService("UserInputService").InputBegan:connect(**onKeyPress**)

I put bold underneath the error and it says: W001: Unknown Global 'OnKeyPress'

5 comments

0

.KeyCode() is not a value inside the onKeyPress function.

0

you can't use userinputservice on the server

0

You also have different capitalization. In the normal script, you define the variable as "OnKeyPress", but you try to access it with "onKeyPress". You have to make them the same spelling and capitalization.

0

Thanks ill try and fix that now :)

0

Did that work?