I want to not have an error.
The issue is that there is an error: attempt to call a nil value On the 19th line of code.
I can’t find a solution.
code:
local runService = game:GetService("RunService")
local collectionService = game:GetService("CollectionService")
local waterGui = game:GetService("Players").LocalPlayer.PlayerGui:WaitForChild("ScreenGui").Water
local camera = workspace.CurrentCamera
local camPosPart = Instance.new("Part")
camPosPart.Parent = workspace
camPosPart.Name = "CameraPos"
camPosPart.Size = Vector3.new(0.001,0.001,0.001)
function touchingWater()
camPosPart.CFrame = camera.CFrame
local touching = workspace:GetPartsInPart(camPosPart)
local notTouchingWater = 0
if touching ~= nil then
for i, part in pairs (touching) do
if collectionService:HasTag(part, "Water") then
waterGui.Visible = true
else
notTouchingWater += 1
end
end
if notTouchingWater == #touching then
waterGui.Visible = false
end
else
waterGui.Visible = false
end
end
runService.RenderStepped:Connect(touchingWater())