Now, I have a script that when I click on terrain based water, it fires a remote event. If mouse.Target returns with terrain, It uses a mouse.UnitRay to find if the patch that was clicked is water. Problem is, it always returns with Enum.Material.Air. The only exception is sometimes when you jam your camera into the ground, it returns what the ground’s material was. I tried ignoring Enum.Material.Air, but it only takes Instances. (I knew that, but it was worth a try.) I am completely out of ideas.
Here is my code: (Raycasting system at 20 - 26, this is all in a local script)
player = game.Players.LocalPlayer
character = player.Character
if not character or not character.Parent then
character = player.CharacterAdded:wait()
end
mouse = player:GetMouse()
event = game.ReplicatedStorage.HarvestEvent
mouse.Button1Down:Connect(function()
local target = mouse.Target
if character:FindFirstChildOfClass("Tool") == nil then
if target then
if target.Name == "Trunk" and player:DistanceFromCharacter(target.Position) <= 15 then
if math.random(1,10) == 10 then
event:FireServer("Stick")
end
target.Parent.Leaves.ParticleEmitter.Enabled = true
wait(1)
target.Parent.Leaves.ParticleEmitter.Enabled = false
elseif target.Name == "Terrain" then
local _, _, _, material = workspace:FindPartOnRay(mouse.UnitRay)
print(material, type(material))
if material == Enum.Material.Water then
player.Thirst.Value = player.Thirst.Value + 25
end
end
end
end
end)