Hello. I am trying to make a mining game where the mining speed is based on the type of terrain that you are hitting. However, there is an error with the script I made to detect the terrain
Here’s the script:
Players = game:GetService("Players")
local function Cast()
local ray = script.Parent.Contents.Ray
local RayParams = RaycastParams.new()
RayParams.FilterType = Enum.RaycastFilterType.Whitelist
RayParams.FilterDescendantsInstances = {game.Workspace.Terrain}
RayParams.IgnoreWater = true
local raycastResult = workspace:Raycast(ray.Position, ray.CFrame.LookVector, RayParams)
end
local function PlayCast()
for i, player in pairs(Players:GetPlayers()) do
local mouse = player:GetMouse()
mouse.Button1Down:Connect(Cast)
end
end
script.Parent.Equipped:Connect(PlayCast)
The error says that on line 15, somehow button1down is incorrect. Can someone help me with this error?
oh, and here’s the error:
attempt to index nil with ‘Button1Down’
this is in a serverscript.