Trouble with getting gui to show while swimming

I’ve used the script below which seems to work perfectly fine above water. It makes a gui visible when the player is in contact with the part the script is inside of, however it doesn’t seem to be working if i place the part in water! I can’t figure out why

script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
		if plr then
			if not plr.PlayerGui:FindFirstChild("boop") then
				local clonedgui = script.Parent:FindFirstChildOfClass("ScreenGui"):Clone()
				clonedgui.Name = "boop"
				clonedgui.Parent = plr.PlayerGui
				script.Parent.TouchEnded:Connect(function(hit2)
					if hit == hit2 then
						game.Debris:AddItem(clonedgui,0)
					end
				end)
			end
		end
	end
end)

I’d appreciate any help!

To my knowledge GUI’s do not render in water by default.

Try adding this into your code:

clonedgui.IgnoreWater = true

Full Code:

script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
		if plr then
			if not plr.PlayerGui:FindFirstChild("boop") then
				local clonedgui = script.Parent:FindFirstChildOfClass("ScreenGui"):Clone()
				clonedgui.Name = "boop"
				clonedgui.IgnoreWater = true
				clonedgui.Parent = plr.PlayerGui
				script.Parent.TouchEnded:Connect(function(hit2)
					if hit == hit2 then
						game.Debris:AddItem(clonedgui,0)
					end
				end)
			end
		end
	end
end)
1 Like

That didn’t work, unfortunately. But thank you for trying!

I’ve managed to put this together and it seems to be working so far

script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") and hit.Parent.Humanoid:GetState() == Enum.HumanoidStateType.Swimming then
		local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
		if plr then
			if not plr.PlayerGui:FindFirstChild("boop") then
				local clonedgui = script.Parent:FindFirstChildOfClass("ScreenGui"):Clone()
				clonedgui.Name = "boop"
				clonedgui.Parent = plr.PlayerGui
				
				local function updateGui()
					if hit.Parent.Humanoid:GetState() == Enum.HumanoidStateType.Swimming then
						clonedgui.Enabled = true
					else
						print("umm no")
					end
				end
				
				script.Parent.TouchEnded:Connect(function(hit2)
					if hit == hit2 then
						game.Debris:AddItem(clonedgui,0)
					end

				end)
				hit.Parent.Humanoid.StateChanged:Connect(updateGui)
				updateGui()
			end
		end
	end
end)

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