I have a script all based around making water realistic, playing with the sounds and now meant to be changing the water transparency, everything about the script works fine, except for one part which is meant to change the transparency of the water when you move the camera in and out of it, this camera in the water system works for the sound so I know that isn’t the problem. The script outputs no errors, but no change to the water transparency, my graphics is turned up so that isn’t the problem, the properties tab doesn’t change when the script is in action, I feel like this should work just fine so either I’m thinking that you can’t locally change the water transparency for a player or that somehow it just isn’t working the way it is meant to. Could someone tell me what is happening?
cam = workspace.CurrentCamera
char = script.Parent
underwater = game.SoundService.Sounds.Underwater
swimming = game.SoundService.Sounds.Swimming
terrain = workspace.Terrain
local humanoid = char:WaitForChild("Humanoid")
local Terrain = game.Workspace.Terrain
local Transparency = Terrain.WaterTransparency
offset = 0.01
while wait() do
local pos = cam.CFrame.Position
local min = Vector3.new(pos.X + offset,pos.Y + offset, pos.Z + offset)
local max = Vector3.new(pos.X - offset,pos.Y - offset, pos.Z - offset)
local region = Region3.new(max, min)
region = region:ExpandToGrid(4)
if region then
local material = game.Workspace.Terrain:ReadVoxels(region, 4)
if material[1][1][1] == Enum.Material.Water then
underwater.Playing = true
swimming.Playing = false
Transparency = 0.02
else
underwater.Playing = false
Transparency = 0.45
if humanoid:GetState() == Enum.HumanoidStateType.Swimming then
swimming.Playing = true
end
end
end
end