WaterColor local script not working?

Hi, I want to make a local script where the player touches a part, and the WaterColor changes when it’s touched.

This output keeps appearing and I’m not quite sure what it means
image

I tried asking a few people, but they weren’t sure what was going on either, so I decided to ask here.

local part = game.Workspace.OOF1

part.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
		game.Workspace.Terrain.WaterColor = Color3.new.fromRGB(88, 166, 74)
    end
end)

part.TouchEnded:Connect(function()
	game.Workspace.Terrain.WaterColor = Color3.new.fromRGB(92, 132, 166)
end)

I’m fairly new to scripting, so please bare with me :slight_smile:

1 Like

You’re saying

Color3.new.fromRGB()

when it should be

Color3.fromRGB()

Color3.new and Color3.fromRGB are two separate constructors.

4 Likes

Hi I have a similar situation where I tried to change the color and the transparency of the water when the player is in a specific area. I tried your script and it sometimes glitched and the water turned back to the default color and transparency, even though I was inside the “CanCollide =” false part.
So, I tried using another way to do this and it literally crashes my game so idk what to do. Here’s the script:

local RegionPart = game.Workspace.RegionPart
local pos1 = RegionPart.Position - (RegionPart.Size / 2)
local pos2 = RegionPart.Position + (RegionPart.size / 2)
local region = Region3.new(pos1, pos2)

while true do
	wait (0.5)
	local partsInRegion = workspace:FindPartsInRegion3(region, nil, 1000)
	for i, part in pairs(partsInRegion) do
		if part.Parent:FindFirstChild("Humanoid") ~= nil then
			print("Player Found in the region!: ".. part.Parent.Name)
			game.Workspace.Terrain.WaterColor = Color3.fromRGB(127,0,0)
			game.Workspace.Terrain.WaterTransparency = 0
		end
		if part.Parent:FindFirstChild("Humanoid") == nil then
			print("player wasn't found in the region")
			game.Workspace.Terrain.WaterColor = Color3.fromRGB(0,0,127)
			game.Workspace.Terrain.WaterTransparency = 1
		end
	end
end

Maybe this works? (I don’t work with Terrain or Region3 that often.)

local RegionPart = game.Workspace.RegionPart
local pos1 = RegionPart.Position - (RegionPart.Size / 2)
local pos2 = RegionPart.Position + (RegionPart.size / 2)
local region = Region3.new(pos1, pos2)

while wait(0.5) do
	local partsInRegion = workspace:FindPartsInRegion3(region, RegionPart, 1000)
	for i, part in pairs(partsInRegion) do
		if part.Parent:FindFirstChild("Humanoid") ~= nil then
			print("Player Found in the region!: ".. part.Parent.Name)
			game.Workspace.Terrain.WaterColor = Color3.fromRGB(127,0,0)
			game.Workspace.Terrain.WaterTransparency = 0
		else
			print("player wasn't found in the region")
			game.Workspace.Terrain.WaterColor = Color3.fromRGB(0,0,127)
			game.Workspace.Terrain.WaterTransparency = 1
		end
	end
end

Also, just create a separate topic as this topic has already been solved and your post does not contribute to solving the issue anyways.

Edit: nvm, just found your topic randomly.