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

i'm trying to make a door but it won't do anything when i press the button to open the door?

Asked by
shackfu 14
5 years ago
local ContextActionService = game:GetService("ContextActionService")
local function EnterDoor(inputState)
    if inputState == Enum.UserInputState.Begin then
        local DoorDistance = (workspace.Door1.Zone.Position - game.Players.LocalPlayer.Character.HumanoidRootPart.Position).magnitude
        if DoorDistance <= 50 then
        print ("you went in the door yay")
        end
    end
end
ContextActionService:BindAction("GoInDoor", EnterDoor, true,"e") 

it doesn't print the thing when i press the button and i don't know why. i don't get any errors when i run it.

0
the e key is an enumeration value , not a string theking48989987 2147 — 5y
0
yea i tried to get some help from someone else they changed the "e" to a different thing but in other scripts where i change controls, it seems to work fine the way i put it as. also it doesn't work for the way the guy put it as either. shackfu 14 — 5y

1 answer

Log in to vote
1
Answered by 5 years ago
Edited 5 years ago

Revised Local Script

local ContextActionService = game:GetService("ContextActionService")
local function EnterDoor(actionName, inputState, inputObj)
    if inputState == Enum.UserInputState.Begin then
        local DoorDistance = (workspace.Door1.Zone.Position - game.Players.LocalPlayer.Character.HumanoidRootPart.Position).magnitude
        if DoorDistance <= 50 then
            print ("you went in the door yay")
        end
    end
end

ContextActionService:BindAction("GoInDoor", EnterDoor, true, Enum.KeyCode.E)

EDITS

A. You need to alter "e" to the actual Enum KeyCode

B. The function for the ContextActionService contains three parameters, the first of which is the action's name, which you had tried to define as the inputstate.

Ad

Answer this question