Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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.

2 comments

0

the e key is an enumeration value , not a string

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.

1 answer

✓ Accepted answer

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.