I have a door system, which when hovered over (with a mouse on a pc/mac), it displays a "Press 'E' to open", but now that it works, I have concerns with mobile devices, such as phones. Is there a function where it checks if the part was tapped on a mobile device?
(I know 'mouse' is considered a legacy function, but even on the devforum I couldn't find a replacement).
Also, is there a better method of security than the one I have? What mine does is that it changes the name of all the parts every 10 seconds.
localscript inside of the player:
--[[
Definitions: 1-21
]]--
local security = require(game:GetService("ReplicatedStorage"):WaitForChild("security"))
local userInputService = game:GetService("UserInputService")
local players = game:GetService("Players")
local player = players.LocalPlayer
local mouse = player:GetMouse()
local char = player.Character
if not char or not char.Parent then
char = player.CharacterAdded:wait()
end
local workSpace = game:GetService("Workspace")
local interactive = workSpace:WaitForChild("Interactive")
local doors = interactive:WaitForChild(_G.Doors)
local tools = interactive:WaitForChild(_G.Tools)
local replicatedStorage = game:GetService("ReplicatedStorage")
local doorEnabled = false
local door
local toolEnabled = false
local tool
--[[
Functions: 22-36
--]]
local hideDoorGui = function()
for i,v in pairs (doors:GetChildren()) do
v:WaitForChild("Gui").Enabled = false
end
for i,v in pairs (tools:GetChildren()) do
v:WaitForChild("Gui").Enabled = false
end
doorEnabled = false
door = nil
toolEnabled = false
tool = nil
end
mouse.Move:Connect(function()
local object = mouse.Target
if object then
if doors:FindFirstChild(object.Name) ~= nil then
if (char.HumanoidRootPart.Position - object.Position).magnitude < 20 then
doorEnabled = true
door = object
object:WaitForChild("Gui").Enabled = true
end
elseif tools:FindFirstChild(object.Name) ~= nil then
if (char.HumanoidRootPart.Position - object.Position).magnitude < 20 then
object:WaitForChild("Gui").Enabled = true
toolEnabled = true
tool = object
end
else
hideDoorGui()
end
else
hideDoorGui()
end
end)
userInputService.InputBegan:connect(function(inputObject, gameProcessedEvent)
if inputObject.KeyCode == Enum.KeyCode.E then
if doorEnabled == true then
if door ~= nil then
replicatedStorage:WaitForChild("Door"):FireServer(door,char)
print("Fired")
end
elseif toolEnabled == true then
if tool ~= nil then
replicatedStorage:WaitForChild("Tool"):FireServer(tool,tool:WaitForChild("toolType").Value)
print("Fired")
end
end
end
end)
Events Script:
local replicatedStorage = game:GetService("ReplicatedStorage")
local TweenService = game:GetService("TweenService")
local openAnimation = Instance.new("Animation")
local pickupAnimation = Instance.new("Animation")
openAnimation.AnimationId = "http://www.roblox.com/Asset?ID=2822903669"
pickupAnimation.AnimationId = "http://www.roblox.com/Asset?ID=2823825483"
replicatedStorage.Door.OnServerEvent:Connect(function(p,door,char)
local animTrack = char.Humanoid:LoadAnimation(openAnimation)
if door:WaitForChild("Values"):WaitForChild("inMotion").Value ~= true then
if door:WaitForChild("Values"):WaitForChild("isOpen").Value ~= true then
door:WaitForChild("Sound"):Play()
door:WaitForChild("Values"):WaitForChild("inMotion").Value = true
animTrack:Play()
local tween = TweenService:Create(door, TweenInfo.new(1,Enum.EasingStyle.Linear), {CFrame = door:WaitForChild("Positions"):WaitForChild("OpenDoorPos").CFrame}) tween:Play() tween.Completed:Wait()
door:WaitForChild("Values"):WaitForChild("inMotion").Value = false
door:WaitForChild("Values"):WaitForChild("isOpen").Value = true
door:WaitForChild("Gui").TextLabel.Text = "Press 'E' to close"
else
door:WaitForChild("Sound"):Play()
door:WaitForChild("Values"):WaitForChild("inMotion").Value = true
animTrack:Play()
local tween = TweenService:Create(door, TweenInfo.new(1,Enum.EasingStyle.Linear), {CFrame = door:WaitForChild("Positions"):WaitForChild("ClosedDoorPos").CFrame}) tween:Play() tween.Completed:Wait()
door:WaitForChild("Values"):WaitForChild("inMotion").Value = false
door:WaitForChild("Values"):WaitForChild("isOpen").Value = false
door:WaitForChild("Gui").TextLabel.Text = "Press 'E' to open"
end
end
end)
replicatedStorage.Tool.OnServerEvent:Connect(function(p,tool,toolType)
local animTrack = p.Character.Humanoid:LoadAnimation(pickupAnimation)
animTrack:Play()
game.ServerStorage.Tools:WaitForChild(toolType):Clone().Parent = p.Backpack
tool:Destroy()
end)
Security Script:
local workSpace = game:GetService("Workspace")
local interactive = workSpace:WaitForChild("Interactive")
local security = require(game:GetService("ReplicatedStorage"):WaitForChild("security"))
local interactive_doors = interactive:WaitForChild("Doors")
local interactive_tools = interactive:WaitForChild("Tools")
local generator = Random.new()
local name = ""
local code_characters = {
--lower case letters
"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z",
--upper case letters
"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z",
--numbers
1,2,3,4,5,6,7,8,9,0,
--special characters
"`","~","!","@","#","$","%","^","&","*","(",")","-","_","=","+","{","}","[","]","\\","|",";",":","\"","\'",",","<",">",".","/","?"
}
wait(1)
while true do
for i,v in pairs (interactive:GetChildren()) do
v.Name = ""
for i = 1, 100 do
local newCharNum = generator:NextInteger(1, #code_characters)
security.changeName(v,code_characters[newCharNum])
end
for i,q in pairs (v:GetChildren()) do
q.Name = ""
for i = 1, 100 do
local newCharNum = generator:NextInteger(1, #code_characters)
security.changeName(q,code_characters[newCharNum])
end
end
end
wait(10)
end
Thanks in advance! Dont hessitate to tell me if I could improve my code too

2 comments
mouse isn't a function but ok
youre gonna want ContextActionService, bud