Hello, I would like to know if someone who could help me with my door system. At the moment my workstation system door with the Keypads function and I would like to put it so that the mobiles can open the doors. I have the script for you and if you can help me it would be nice.
---------------------- /// DOOR SYSTEM \\\ ----------------------
character:WaitForChild("Humanoid").Changed:Connect(function()
if character.Humanoid.Health == 0 then return end
for i,v in pairs (workspace.Mechanical:GetChildren()) do
local Magnitude1
local Magnitude2
if v.Name == 'DoorS' or v.Name == 'DoorCheckpointS' then
Magnitude1 = (character.HumanoidRootPart.Position - v.Main.Door1.DetectionPoint1.Position).magnitude
Magnitude2 = (character.HumanoidRootPart.Position - v.Main.Door1.DetectionPoint2.Position).magnitude
elseif v.Name == 'DoorArmorS' or v.Name == 'DoorN' then
Magnitude1 = (character.HumanoidRootPart.Position - v.Main.DoorLeft.DetectionPoint1.Position).magnitude
Magnitude2 = (character.HumanoidRootPart.Position - v.Main.DoorRight.DetectionPoint2.Position).magnitude
elseif v.Name == 'DoorGate' then
Magnitude1 = (character.HumanoidRootPart.Position - v.Main.Door1.Main.Position).magnitude
Magnitude2 = (character.HumanoidRootPart.Position - v.Main.Door1.Main.Position).magnitude
end
if Magnitude1 < 6 or Magnitude2 < 6 then
if v.Name == 'DoorS' then
if Magnitude1 < Magnitude2 then
Information.Direction = 'Left'
else
Information.Direction = 'Right'
end
end
Information.Door = v
doorInstruction.Visible = true
spawn(function()
if not character.HumanoidRootPart:FindFirstChild('Attachment') then
local f = v.Frame:FindFirstChild('Frame') or v.Frame:FindFirstChild('Union')
local Beam = game.ReplicatedStorage.Assets.DoorBeam:Clone()
Beam.Parent = character.HumanoidRootPart
local At1 = Instance.new('Attachment',f)
local At2 = Instance.new('Attachment',character.HumanoidRootPart)
Beam.Attachment0 = At1
Beam.Attachment1 = At2
local thing = game.ReplicatedStorage.Assets.Yes_Thing:Clone()
thing.Parent = At1
repeat
for _, line in pairs(At1.Yes_Thing.Background.Lines:GetChildren()) do
game:GetService("TweenService"):Create(line, TweenInfo.new(0.2), {Position = require(line.Positions).outwardsPosition}):Play()
end
wait(0.5)
game:GetService("TweenService"):Create(At1.Yes_Thing.Background, TweenInfo.new(0.4), {Rotation = At1.Yes_Thing.Background.Rotation + 90}):Play()
wait(0.5)
for _, line in pairs(At1.Yes_Thing.Background.Lines:GetChildren()) do
game:GetService("TweenService"):Create(line, TweenInfo.new(0.2), {Position = require(line.Positions).inwardsPosition}):Play()
end
wait(1.0)
until Information.Door ~= v or character.Humanoid.Health == 0
Beam:Destroy()
At1:Destroy()
At2:Destroy()
thing:Destroy()
end
end)
elseif Information.Door then
local Magnitude1,Magnitude2
if Information.Door.Name == 'DoorS' or Information.Door.Name == 'DoorCheckpointS' then
Magnitude1 = (character.HumanoidRootPart.Position - Information.Door.Main.Door1.DetectionPoint1.Position).magnitude
Magnitude2 = (character.HumanoidRootPart.Position - Information.Door.Main.Door1.DetectionPoint2.Position).magnitude
elseif Information.Door.Name == 'DoorArmorS' or Information.Door.Name == 'DoorN' then
Magnitude1 = (character.HumanoidRootPart.Position - Information.Door.Main.DoorLeft.DetectionPoint1.Position).magnitude
Magnitude2 = (character.HumanoidRootPart.Position - Information.Door.Main.DoorRight.DetectionPoint2.Position).magnitude
elseif Information.Door.Name == 'DoorGate' then
Magnitude1 = (character.HumanoidRootPart.Position - Information.Door.Main.Door1.Main.Position).magnitude
Magnitude2 = (character.HumanoidRootPart.Position - Information.Door.Main.Door1.Main.Position).magnitude
end
if Magnitude1 > 9 and Magnitude2 > 9 then
doorInstruction.Visible = false
Information.Door = nil
Information.Direction = nil
end
end
end
end)
InputService.InputBegan:Connect(function(Key,Chat)
if Key.KeyCode == Enum.KeyCode.T and not Chat and Information.Door ~= nil then
Information.Door.Door.Open:FireServer(script,Information.Direction)
end
end)
game.ReplicatedStorage.RemoteEvents.Doors.MakeMessage.OnClientEvent:Connect(function(Message)
doorReason.TextLabel.TextColor3 = Colors[Message]
for i=1,#Message do
wait(0.01)
doorReason.Text = string.sub(Message,1,i)
doorReason.TextLabel.Text = string.sub(Message,1,i)
end
wait(3)
repeat
wait(0.01)
doorReason.TextTransparency = doorReason.TextTransparency+.1
doorReason.TextLabel.TextTransparency = doorReason.TextTransparency
until doorReason.TextTransparency >= 1
doorReason.Text = ''
doorReason.TextLabel.Text = ''
doorReason.TextTransparency = 0
doorReason.TextLabel.TextTransparency = 0
end)
Use ContextActionService instead of UserInputService to create buttons on a mobile player’s screen. Buttons will share the same callback with keyboard buttons
If you read through the documentation you will see that converting it is very simple. You just need to move the code inside the InputBegan callback into a function that will be bound to a KeyCode.
By reading the documentation you will immediately understand how to modify your code.
local ContextActionService = game:GetService("ContextActionService")
function ECallback()
if Information.Door ~= nil then
Information.Door.Door.Open:FireServer(script,Information.Direction)
end
end
ContextActionService:BindAction("OpenDoor", ECallback, true, Enum.KeyCode.E) --true is a bool indicating that a button should be created on mobile screens, the button will invoke ECallback as pressing E on the keyboard would
Me, who is French, it’s not always easy to watch videos or documents that are in English. Its for its that I created a post to found a person could modify it.
local CAS = game:GetService("ContextActionService") --CAS stands for Context Action Service
---------------------- /// DOOR SYSTEM \\\ ----------------------
character:WaitForChild("Humanoid").Changed:Connect(function()
if character.Humanoid.Health == 0 then return end
for i,v in pairs (workspace.Mechanical:GetChildren()) do
local Magnitude1
local Magnitude2
if v.Name == 'DoorS' or v.Name == 'DoorCheckpointS' then
Magnitude1 = (character.HumanoidRootPart.Position - v.Main.Door1.DetectionPoint1.Position).magnitude
Magnitude2 = (character.HumanoidRootPart.Position - v.Main.Door1.DetectionPoint2.Position).magnitude
elseif v.Name == 'DoorArmorS' or v.Name == 'DoorN' then
Magnitude1 = (character.HumanoidRootPart.Position - v.Main.DoorLeft.DetectionPoint1.Position).magnitude
Magnitude2 = (character.HumanoidRootPart.Position - v.Main.DoorRight.DetectionPoint2.Position).magnitude
elseif v.Name == 'DoorGate' then
Magnitude1 = (character.HumanoidRootPart.Position - v.Main.Door1.Main.Position).magnitude
Magnitude2 = (character.HumanoidRootPart.Position - v.Main.Door1.Main.Position).magnitude
end
if Magnitude1 < 6 or Magnitude2 < 6 then
if v.Name == 'DoorS' then
if Magnitude1 < Magnitude2 then
Information.Direction = 'Left'
else
Information.Direction = 'Right'
end
end
Information.Door = v
doorInstruction.Visible = true
spawn(function()
if not character.HumanoidRootPart:FindFirstChild('Attachment') then
local f = v.Frame:FindFirstChild('Frame') or v.Frame:FindFirstChild('Union')
local Beam = game.ReplicatedStorage.Assets.DoorBeam:Clone()
Beam.Parent = character.HumanoidRootPart
local At1 = Instance.new('Attachment',f)
local At2 = Instance.new('Attachment',character.HumanoidRootPart)
Beam.Attachment0 = At1
Beam.Attachment1 = At2
local thing = game.ReplicatedStorage.Assets.Yes_Thing:Clone()
thing.Parent = At1
repeat
for _, line in pairs(At1.Yes_Thing.Background.Lines:GetChildren()) do
game:GetService("TweenService"):Create(line, TweenInfo.new(0.2), {Position = require(line.Positions).outwardsPosition}):Play()
end
wait(0.5)
game:GetService("TweenService"):Create(At1.Yes_Thing.Background, TweenInfo.new(0.4), {Rotation = At1.Yes_Thing.Background.Rotation + 90}):Play()
wait(0.5)
for _, line in pairs(At1.Yes_Thing.Background.Lines:GetChildren()) do
game:GetService("TweenService"):Create(line, TweenInfo.new(0.2), {Position = require(line.Positions).inwardsPosition}):Play()
end
wait(1.0)
until Information.Door ~= v or character.Humanoid.Health == 0
Beam:Destroy()
At1:Destroy()
At2:Destroy()
thing:Destroy()
end
end)
elseif Information.Door then
local Magnitude1,Magnitude2
if Information.Door.Name == 'DoorS' or Information.Door.Name == 'DoorCheckpointS' then
Magnitude1 = (character.HumanoidRootPart.Position - Information.Door.Main.Door1.DetectionPoint1.Position).magnitude
Magnitude2 = (character.HumanoidRootPart.Position - Information.Door.Main.Door1.DetectionPoint2.Position).magnitude
elseif Information.Door.Name == 'DoorArmorS' or Information.Door.Name == 'DoorN' then
Magnitude1 = (character.HumanoidRootPart.Position - Information.Door.Main.DoorLeft.DetectionPoint1.Position).magnitude
Magnitude2 = (character.HumanoidRootPart.Position - Information.Door.Main.DoorRight.DetectionPoint2.Position).magnitude
elseif Information.Door.Name == 'DoorGate' then
Magnitude1 = (character.HumanoidRootPart.Position - Information.Door.Main.Door1.Main.Position).magnitude
Magnitude2 = (character.HumanoidRootPart.Position - Information.Door.Main.Door1.Main.Position).magnitude
end
if Magnitude1 > 9 and Magnitude2 > 9 then
doorInstruction.Visible = false
Information.Door = nil
Information.Direction = nil
end
end
end
end)
function ECallback()
if Information.Door ~= nil then
Information.Door.Door.Open:FireServer(script,Information.Direction)
end
end
CAS:BindAction("OpenDoor", ECallback, true, Enum.KeyCode.E) --true is a bool indicating that a button should be created on mobile screens, the button will invoke ECallback as pressing E on the keyboard would
game.ReplicatedStorage.RemoteEvents.Doors.MakeMessage.OnClientEvent:Connect(function(Message)
doorReason.TextLabel.TextColor3 = Colors[Message]
for i=1,#Message do
wait(0.01)
doorReason.Text = string.sub(Message,1,i)
doorReason.TextLabel.Text = string.sub(Message,1,i)
end
wait(3)
repeat
wait(0.01)
doorReason.TextTransparency = doorReason.TextTransparency+.1
doorReason.TextLabel.TextTransparency = doorReason.TextTransparency
until doorReason.TextTransparency >= 1
doorReason.Text = ''
doorReason.TextLabel.Text = ''
doorReason.TextTransparency = 0
doorReason.TextLabel.TextTransparency = 0
end)
Sorry i made a mistake writing it. Did you get a reference error saying that :BindAction() is not a valid function of ContexActionService or that ContextActionService is nil? I wrote ContextActionService instead of CAS which was the correctly defined variable
Please share the error message and If your code is using ContextActionService:BindAction("OpenDoor", ECallback, true, Enum.KeyCode.E) then it will error as a variable named ContextActionService is never declared. Change ContextActionService to CAS (because that’s how the reference to ContextActionService is declared) and it should not produce an error anymore