Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I make a Tool stealing script by contact?

Asked by 5 years ago
Edited 5 years ago

If Player 1 touches a Tool in Player 2's inventory, Player 1 will take the Tool, and Player 2 will no longer have it.

Here's the current scripts

Tool = script.Parent


function fire(v)

    Tool.Handle.Boing:play()

    local vCharacter = Tool.Parent
    local vPlayer = game.Players:playerFromCharacter(vCharacter)

    local spawnPos = vCharacter.PrimaryPart.Position
    spawnPos  = spawnPos + (v * 7)

--[[
    local missile = Instance.new("Part")

    missile.Position = spawnPos
    missile.Size = Vector3.new(2,2,2)
    missile.Velocity = v * 10000000000000000000000000000000000000
    missile.BrickColor = BrickColor.random() -- BrickColor.new(26)
    missile.Shape = 0
    missile.BottomSurface = 0
    missile.TopSurface = 0
    missile.Name = "Cannon Shot"
    missile.Elasticity = 5
    missile.Reflectance = .2
    missile.Friction = 0

    Tool.Handle.Boing:clone().Parent = missile



    local new_script = script.Parent.CannonBall:clone()
    new_script.Disabled = false
    new_script.Parent = missile

    local creator_tag = Instance.new("ObjectValue")
    creator_tag.Value = vPlayer
    creator_tag.Name = "creator"
    creator_tag.Parent = missile



    missile.Parent = game.Workspace
]]

    connection:disconnect()
    wait()
    Tool.Parent = game.Workspace
    Tool.Handle.Position = spawnPos
    Tool.Handle.Velocity = v * 107.5
end



--Tool.Enabled = true
function onActivated()

    --if not Tool.Enabled then
    --  return
    --end

    --Tool.Enabled = false

    local character = Tool.Parent;
    local humanoid = character.Humanoid
    if humanoid == nil then
        print("Humanoid not found")
        return 
    end

    local targetPos = humanoid.TargetPoint
    local lookAt = (targetPos - character.Head.Position).unit

    fire(lookAt)

    --wait(2)

    --Tool.Enabled = true
end

while true do
script.Parent.Activated:wait()
connection = game:service("RunService").Stepped:connect(onActivated)
wait(2)
end


--connection = script.Parent.Activated:connect(onActivated)


(it's used for throwing the ball).

while true do
wait()
if script.Parent.Parent.Name == "Backpack" then
script.Parent.Parent = script.Parent.Parent.Parent.Character
end
end

(it's used for never hiding the Tool in the inventory)

I've tried everything, and I can't seem to get a working script for this problem. Please help me out.

stealrate = 1 -- adjust how fast you want the ball to be able to be stolen.
wait(stealrate)-- waiting before it can be stolen again, adjust above.
script.Parent.Handle.Touched:connect(function(hit) 


pcall(function() 
player = game.Players:getPlayerFromCharacter(hit.Parent) 
script.Parent:Clone().Parent = player.Backpack 
script.Parent:Remove() 



end) 
end)

was a script I used. It duplicated the tool when stolen.

0
“I’ve tried everything” doesn’t help me identify your issue here. Telling me examples of some of your attempts, will. T0XN 276 — 5y
0
I've edited the thread to show my attempts kenappleby -8 — 5y

Answer this question