So I am trying to make an interaction system where you cannot see the GUI or press “E” if you are facing a wall Like Line of sight, I have tried using Raycast but it has not turned out well, what should I do?
Some Info:
You need to be 20 studs near
It works in Any wall
Note : No, i dont want proximityprompt
The current Script:
wait(0.1)
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 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 vector, onScreen = camera:WorldToScreenPoint(v.Position)
if (rootpart.Position - v.Position).Magnitude <= 20 and onScreen then
if not ShowCooldown then
ShowCooldown = true
local guiclone = board:Clone()
guiclone.Parent = v
-- item is on screen and player is within 20 studs
end
else
if ShowCooldown then
if v:FindFirstChild("InteractionGui") then
ShowCooldown = false
v.InteractionGui:Destroy()
end
end
end
end
end
end
end
end)
uis.InputBegan:Connect(function(input, GameProcessed, IsTyping)
if IsTyping then
print("No writing pls.")
return
elseif 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)