Need a pro who knows raycasting

I created a shovel that scoops dirt like in the game “The Underground War” but it suddenly stopped working. The scripts provided literally works but they just stoped. The raycastResult is printing as nil.

Client Script in the shovel.

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()

local debounce = false

script.Parent.Activated:Connect(function()
	print("YES")
	if not debounce then
		debounce = true
		
		local raycastParams = RaycastParams.new()
		raycastParams.FilterType = Enum.RaycastFilterType.Whitelist
		raycastParams.FilterDescendantsInstances = {script.Parent}
		
		local raycastResult = workspace:Raycast(character:WaitForChild("HumanoidRootPart").CFrame.Position, character:WaitForChild("HumanoidRootPart").CFrame.LookVector * 10, raycastParams)
		
		warn(raycastResult)
		
		if raycastResult then
			local hit = raycastResult.Instance
			local position = raycastResult.Position
			
			script.Parent:WaitForChild("Dig"):FireServer(hit, position)
		end
		
		wait(0.5)
		debounce = false
	end
end)

Server Script inside the shovel

script.Parent:WaitForChild("Dig").OnServerEvent:Connect(function(player, hit, position)
	print("FIRED")
	if hit.Parent == workspace:WaitForChild("Dirt") then
		print(hit.Transparency)
		hit.Transparency += 0.25
		
		if hit.Transparency >  0.75 then
			hit:Destroy()
		end
	else
		print("NOPE")
	end
end)

Are you sure you meant to whitelist only the shovel? Or did you mean to blacklist the entire character including the shovel?

what is the difference between white/black list?

A whitelist looks for ONLY THOSE items, where a blacklist looks for everything EXCEPT for those items.

2 Likes

So I should white list the tool and character so the script ignores them?

The “nil” is the raycast result

Probably something with this line and the direction of the ray?

1 Like

You dont need the position I am pretty sure.

You also dont have to wait for the humanoid root part twice because if you wait once then the second time the humanoidRoot will already be loaded in.

1 Like

Change it to blacklist instead of whitelist
Change filterdescendantsinstance to the character

That should solve your problem

2 Likes

Its lookVector not LookVector I am also sure of this…

Maybe because your warning Raycast? It will probably return nil the second the script runs. I recommend putting it inside the if statement:

if raycastResult then

then check again, the if statement will check if its not nil, and if it isn’t, it will fire and give some sort of result

1 Like

Capitalization doesn’t matter with lookvector pretty sure

Hello Zompocolypse!

Change your raycastParams.FilterType to Enum.RaycastFilterType.Blacklist instead of Enum.RaycastFilterType.Whitelist

once again, change it to BLACKLIST instead of WHITELIST

This should fix your issues.

2 Likes