Hello scripters :> I’m trying to make an ability where the player summons a ball of water when their mouse is hovering over Terrain water. I know most of what I need to do for the script but I don’t know how to check if the mouse is touching water and not other types of terrain.
here’s what I have so far:
local UIS = game:GetService("UserInputService")
local RS = game:GetService("ReplicatedStorage")
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local character = player.Character
local waterBall = RS.waterBall:Clone()
local target = mouse.Target
UIS.InputBegan:Connect(function(input,gameprocessed)
if gameprocessed then return end
if input.KeyCode == Enum.KeyCode.Q then
if mouse.Target == workspace.Terrain then
end
end
end)
local underwater = game.Workspace.underwater
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
if mouse.Target = underwater then
end)
`local underwater = game.Workspace.underwater
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
You can send a raycast from the player’s character towards the position of the mouse. Here is an example:
local UserInputService = game:GetService("UserInputService")
local Players = game:GetService("Players")
local rayParams = RaycastParams.new()
rayParams.FilterType = Enum.RaycastFilterType.Whitelist
rayParams.FilterDescendantsInstances = {workspace.Terrain}
rayParams.IgnoreWater = false
local plr = Players.LocalPlayer
local character = plr.Character or plr.CharacterAdded:Wait()
local mouse = plr:GetMouse()
UserInputService.InputBegan:Connect(function(i,isTyping)
if isTyping then return end
if i.KeyCode == Enum.KeyCode.Q then
local raycast = workspace:Raycast(character.HumanoidRootPart.Position, (mouse.Hit.p - character.HumanoidRootPart.Position).Unit * 1000,rayParams)
if raycast and raycast.Material == Enum.Material.Water then
print("Mouse hit water!")
end
end
end)