Attempt to index nil with 'SubtractAsync'

I am trying to make a tool that slices things in half but i get an error “attempt to index nil with ‘SubtractAsync’”

local script

local player = game.Players.LocalPlayer
local backpack = player:WaitForChild("Backpack")

local tool = Instance.new("Tool")
tool.RequiresHandle = false
tool.CanBeDropped = false 
tool.Parent = backpack

tool.Equipped:Connect(function(mouse)
	mouse.Button1Down:Connect(function()
		if mouse.Target and mouse.Target.Parent then
			local part1 = mouse.Target
			local part2 = part1:Clone()
			wait()
			local neg1 = Instance.new("Part")
			local neg2 = Instance.new("Part")
			neg1.Position = Vector3.new(part1.Position.X,part1.Position.Y + part1.Size.Y / 2,part1.Position.Z)
			neg2.Position = Vector3.new(part2.Position.X,part2.Position.Y - part2.Size.Y / 2,part2.Position.Z)
			neg1.Size = Vector3.new(part1.Size.X,part1.Size.Y + part1.Position.Y / 2,part1.Size.Z)
			neg2.Size = Vector3.new(part2.Size.X,part2.Size.Y - part2.Position.Y / 2,part2.Size.Z)
			wait()
			game.ReplicatedStorage.SlashEvent:FireServer(player,neg1,neg2,part1,part2)
		end
	end)
end)

server script

game.ReplicatedStorage.SlashEvent.OnServerEvent:Connect(function(player,neg1,neg2,part1,part2)
   local n1 = {neg1}
   local n2 = {neg2}
   local newUnion1 = part1:SubtractAsync(n1)
   local newUnion2 = part2:SubtractAsync(n2)
end)

It’s because you’re creating the part on the client, it doesn’t exist on the server. You would have to pass the size and CFrame to the server and create the part on the server.

3 Likes

You’re also firing the server with the player variable. You don’t need to send the player variable to the server, because it’s already preset. You only need to do that to fire the client.

1 Like

Ok i did that but i got the error: Position is not a valid member of Player “Players.nuexr”

The player is automatically passed as the first argument as @benpinpop said.

i removed the player thing from the function and it still gave that error