Basically I have an Press E to Interact with objects/parts, but i think on my opinion, is a big MESS, any suggestions or a quick way to get all Models and childrens inside the model of the model?, or anyways
I just repeated all the things in a painfull way i guess
wait(0.16)
local uis = game:GetService("UserInputService")
local Serverwerkspace = workspace
local camera = game:GetService("Workspace").CurrentCamera
--local board = script:WaitForChild("InteractionGui")
local board = game:GetService("ReplicatedStorage").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") or v:IsA("Part") 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
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
if v:FindFirstChild("InteractionGui") then
if v:FindFirstChild("_Interactable") 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.15, Enum.EasingStyle.Quart, Enum.EasingDirection.Out, 0, true, 0)
wait()
local sizetween = ts:Create(frame, tweenInfo, { Size = UDim2.new(0.10, 25,0.10, 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
character.Humanoid.Died:Connect(function()
if v:FindFirstChild("InteractionGui") then
print("Deleted Incorrect GUI Given")
v.InteractionGui:Destroy()
end
end)
end
end
----------------------------
if v:IsA("Folder") then
for i, index in pairs(v:GetChildren()) do
if index:IsA("BasePart") or index:IsA("Part") and index:FindFirstChild("_Interactable") then
if index:FindFirstChild("Event") then
local position = index.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(index.Position)
--if (rootpart.Position - v.Position).Magnitude <= 20 and onScreen then
if raycastResult and (index == raycastResult.Instance) and (rootpart.Position - index.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 = index
-- item is on screen and player is within 20 studs
end
else
if ShowCooldown then
print("Wall Blocking Or Not In Screen")
if index:FindFirstChild("InteractionGui") then
ShowCooldown = false
index.InteractionGui:Destroy()
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
if index:FindFirstChild("InteractionGui") then
if index:FindFirstChild("_Interactable") then
if not PressCooldown then
PressCooldown = true
local vector, onScreen = camera:WorldToScreenPoint(index.Position)
--local myRay = Ray.new(rootpart.Position, v.Position/CFrame)
if (rootpart.Position - index.Position).Magnitude <= 20 and onScreen then -- camera:WorldToScreenPoint(v.Position)
--print("You Pressed E")
local guicloned = index.InteractionGui
local frame = guicloned.InteractionFrame
local tweenInfo = TweenInfo.new(0.15, Enum.EasingStyle.Quart, Enum.EasingDirection.Out, 0, true, 0)
wait()
local sizetween = ts:Create(frame, tweenInfo, { Size = UDim2.new(0.10, 25,0.10, 25)})
sizetween:Play()
index.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
character.Humanoid.Died:Connect(function()
if index:FindFirstChild("InteractionGui") then
print("Deleted Incorrect GUI Given")
index.InteractionGui:Destroy()
end
end)
end
end
end
if v:IsA("Model") then
for i, index2 in pairs(v:GetChildren()) do
if index2:IsA("BasePart") or index2:IsA("Part") and index2:FindFirstChild("_Interactable") then
if index2:FindFirstChild("Event") then
local position = index2.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(index2.Position)
--if (rootpart.Position - v.Position).Magnitude <= 20 and onScreen then
if raycastResult and (index2 == raycastResult.Instance) and (rootpart.Position - index2.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 = index2
-- item is on screen and player is within 20 studs
end
else
if ShowCooldown then
print("Wall Blocking Or Not In Screen")
if index2:FindFirstChild("InteractionGui") then
ShowCooldown = false
index2.InteractionGui:Destroy()
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
if index2:FindFirstChild("InteractionGui") then
if index2:FindFirstChild("_Interactable") then
if not PressCooldown then
PressCooldown = true
local vector, onScreen = camera:WorldToScreenPoint(index2.Position)
--local myRay = Ray.new(rootpart.Position, v.Position/CFrame)
if (rootpart.Position - index2.Position).Magnitude <= 20 and onScreen then -- camera:WorldToScreenPoint(v.Position)
--print("You Pressed E")
local guicloned = index2.InteractionGui
local frame = guicloned.InteractionFrame
local tweenInfo = TweenInfo.new(0.15, Enum.EasingStyle.Quart, Enum.EasingDirection.Out, 0, true, 0)
wait()
local sizetween = ts:Create(frame, tweenInfo, { Size = UDim2.new(0.10, 25,0.10, 25)})
sizetween:Play()
index2.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
end
end
end)
--------------------------------------------------------------