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

How can i get the functions to connect with eachother throughout the scripts?

Asked by 7 years ago

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'

0
.KeyCode() is not a value inside the onKeyPress function. Reshiram110 147 — 7y
0
you can't use userinputservice on the server User#10445 15 — 7y
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. GoldenPhysics 474 — 7y
0
Thanks ill try and fix that now :) Karl_RBX 11 — 7y
0
Did that work? GoldenPhysics 474 — 7y

Answer this question