How I Would Implement My Interaction System For Mobile Users?
Script :
wait(0.16)
local uis = game:GetService("UserInputService")
local Serverwerkspace = workspace
local camera = game:GetService("Workspace").CurrentCamera
local board = script:WaitForChild("InteractionGui")
local ts = game:GetService("TweenService")
local player = game.Players.LocalPlayer
local character = player.Character
wait()
local head = character:WaitForChild("Head")
local rootpart = character:WaitForChild("HumanoidRootPart")
local ShowCooldown = false
local PressCooldown = false
--local MAX_DISTANCE = 35
game:GetService("RunService").Stepped:Connect(function()
for i, v in pairs(game.Workspace:GetChildren()) do
if v:IsA("BasePart") then
if v:FindFirstChild("_Interactable") then
if v:FindFirstChild("Event") then
local position = v.Position
local cameraPosition = camera.CFrame.Position
local raycastParams = RaycastParams.new()
wait()
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
raycastParams.FilterDescendantsInstances = {game:GetService('Players').LocalPlayer.Character}
local raycastResult = workspace:Raycast(cameraPosition, position - cameraPosition, raycastParams)
local vector, onScreen = camera:WorldToScreenPoint(v.Position)
--if (rootpart.Position - v.Position).Magnitude <= 20 and onScreen then
if raycastResult and (v == raycastResult.Instance) and (rootpart.Position - v.Position).Magnitude <= 20 and (head.CFrame.p - camera.CFrame.p).Magnitude <= 30 and onScreen then
if not ShowCooldown then
print("In Screen And No Wall In-front")
ShowCooldown = true
local guiclone = board:Clone()
guiclone.Parent = v
-- item is on screen and player is within 20 studs
end
else
if ShowCooldown then
print("Wall Blocking Or Not In Screen")
if v:FindFirstChild("InteractionGui") then
ShowCooldown = false
v.InteractionGui:Destroy()
end
end
end
end
end
end
end
end)
uis.InputBegan:Connect(function(input, IsTyping)
if IsTyping then return end
if input.KeyCode == Enum.KeyCode.E then
--game:GetService("RunService").Stepped:Connect(function()
--local camCFrame = game:GetService("Workspace").CurrentCamera.CFrame.Position
for i, v in pairs(game.Workspace:GetChildren()) do
if v:IsA("BasePart") then
if v:FindFirstChild("InteractionGui") then
if v:FindFirstChild("_Interactable") then
if v:FindFirstChild("Event") then
if not PressCooldown then
PressCooldown = true
local vector, onScreen = camera:WorldToScreenPoint(v.Position)
--local myRay = Ray.new(rootpart.Position, v.Position/CFrame)
if (rootpart.Position - v.Position).Magnitude <= 20 and onScreen then -- camera:WorldToScreenPoint(v.Position)
--print("You Pressed E")
local guicloned = v.InteractionGui
local frame = guicloned.InteractionFrame
local tweenInfo = TweenInfo.new(0.13, Enum.EasingStyle.Quart, Enum.EasingDirection.InOut, 0, true, 0)
wait()
local sizetween = ts:Create(frame, tweenInfo, { Size = UDim2.new(0.25, 25,0.25, 25)})
sizetween:Play()
v.Event:FireServer()
wait(0.2)
PressCooldown = false
-- item is on screen and player is within 20 studs
end
end
end
end
end
end
end
--end)
end
end)