Local scripts can't access gui in PlayerGui

I’d like to have a local script to access a ScreenGui.
The issue is that it just can’t.
I have tried WaitForChild() and just the normal

PlayerGui.ScreenGui

and also FindFirstChild()

Here is my 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.Name = "CameraPos"
camPosPart.Size = Vector3.new(0.001,0.001,0.001)

function touchingWater()
	local touching = workspace:GetPartsInPart(camPosPart)
	local notTouchingWater = 0
	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
end

runService.RenderStepped:Connect()

youre not calling the touchingWater function anywhere

omg :man_facepalming: I’ll try it with it being called

notTouchingWater += 1

This throws an error: attempt to call a nil value (I think)

I updated the code and now there arent any errors. I’ll mark as solved

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.