Hi,
I have a NPC scrpt that allows players to walk up to the NPC and press E to begin a dialog gui. This works fine on a PC but on a mobile device there is no way to press the E key. How do i go about adding an alternative option for mobile players.
local UIS = game:GetService("UserInputService")
local Template = script.Parent:WaitForChild("Template")
local E = script.Parent.Parent:WaitForChild("DetectorPopUp"):WaitForChild("Key")
local Player = game:GetService("Players").LocalPlayer
repeat wait() until Player.Character
local Character = Player.Character
local RootPart = Character:WaitForChild("HumanoidRootPart")
local VarHolder
local Text
local CurrentTrigger
local NPC
local db
local abletochange = true
local StoredValues = {}
local function DisableMove()
if(Character.Humanoid.WalkSpeed~=0)then
StoredValues = {Character.Humanoid.WalkSpeed,Character.Humanoid.JumpPower}
Character.Humanoid.WalkSpeed = 0
Character.Humanoid.JumpPower = 0
end
end
local function EnableMove()
Character.Humanoid.WalkSpeed = StoredValues[1]
Character.Humanoid.JumpPower = StoredValues[2]
end
RootPart.Touched:Connect(function(otherPart)
if(otherPart.Name=="Detector")then
CurrentTrigger = otherPart.NPCTitle.Value
E.Visible = true
E.Parent.Adornee = otherPart
NPC = otherPart.Parent.NPC
end
end)
RootPart.TouchEnded:Connect(function(otherPart)
if(otherPart.Name=="Detector")then
CurrentTrigger = nil
E.Visible = false
E.Parent.Adornee = nil
NPC = nil
end
end)
UIS.InputBegan:Connect(function(inputObject, gameProcessedEvent)
if(inputObject.KeyCode==Enum.KeyCode.E)and(not(db))then
if(CurrentTrigger)then
SetNewNpc()
end
end
end)
function SetNewNpc()
if(abletochange)then
VarHolder = NPC.Parent.Detector
TextValue = VarHolder.Text
Text = TextValue.Value
SetNewTextBox()
end
end
function SetNewTextBox()
if(not(db))then
db = true
DisableMove()
local TextBox = Template:Clone()
TextBox.Parent = script.Parent
TextBox.Text = ""
TextBox.Size = UDim2.new(0,500,0,100)
TextBox.Position = UDim2.new(0.5,-250,1,-150)
TextBox.Visible = true
for i=1,string.len(Text) do
TextBox.Text = string.sub(Text, 1, i)
wait(0.02)
end
UIS.InputBegan:Wait()
TextBox:Destroy()
if(TextValue:FindFirstChildOfClass("StringValue"))then
VarHolder = TextValue
TextValue = VarHolder.Text
Text = TextValue.Value
abletochange = false
db = false
SetNewTextBox()
else
EnableMove()
wait(1)
db = false
abletochange = true
end
end
end