Code issues - script problems with tools

Hello, i want to know what’s wrong in my code.
I need to do that, if the player has the ball tool in his inventory he cannot take the bat tool, and in the same way for the bat tool, how can I do that?:scream:

Example:
I have ball tool → i cannot take bat tool
I have bat tool → i cannot take the ball tool

image

localscript:

local tool = script.Parent
local player = game:GetService("Players").LocalPlayer

if workspace.FilteringEnabled then
	tool.Activated:Connect(function()
		local mouse = player:GetMouse()
		mouse.Button1Down:Connect(function()
			tool.RemoteEvent:FireServer(mouse.hit.p)
		end)
	end)
end

script:

local tool = script.Parent
tool.RemoteEvent.OnServerEvent:Connect(function(player, event)
	local mouse = player:GetMouse()
	local Handle = tool.Handle
	tool.Parent = workspace
	Handle.CFrame = CFrame.new(Handle.Position, event)

	local bv = Instance.new("BodyVelocity",Handle)
	bv.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
	bv.Velocity = tool.Handle.CFrame.LookVector * 70 -- Change the number if you want :D
	
	local vel = tool.Handle.CFrame.LookVector
	
	wait(.1)
	tool.Handle.BodyVelocity:Destroy()

	--- Adding the next part will result when they touch it then will like teleport to the position of the ball and like "take" it
	Handle.Touched:Connect(function(hit)
		if hit.Parent:FindFirstChild("Humanoid") then
			-- tool check
			local tnot = script.Parent.Parent.Bat
			local hastool = false
			local tool = script.Parent.Parent.Ball
			if player.Character:FindFirstChild(tool.Name) or player.Backpack:FindFirstChild(tool.Name)  then
				hastool = true
				Handle.Anchored = false
				wait(.1)
				Handle.Anchored = true
				Handle.Anchored = false
				hastool = false
			elseif player.Character:FindFirstChild(tnot.Name) or player.Backpack:FindFirstChild(tnot.Name) then
				print("You already have the ball, you can't have the bat too.")
			end -- end
		end
	end)
end)

script.Parent.Equipped:Connect(function()
	for i = 0, -4, -.5 do
		script.Parent.GripPos = Vector3.new(0,i,0)
		wait()
	end

	for i = -4,0,.5 do
		script.Parent.GripPos = Vector3.new(0,i,0)
		wait()
	end
end)

First off, I don’t know why you’re checking for workspace.FilteringEnabled in your client script because it’s always enabled by default and you can’t change it.

If you don’t want everyone to spawn with the Ball and the Bat then don’t put them in StarterPack and just give the correct tool to the correct player from the server

3 Likes

I want the players with a bat to only hit the ball and not take the ball, I have the code of the ball implemented so that it can be taken by everyone and that is the problem :frowning:

I need to make sure they can receive the ball but if they are with the bat they won’t receive it