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?
Example:
I have ball tool → i cannot take bat tool
I have bat tool → i cannot take the ball tool
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)