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

My script to print something when activate a tool wont work. How do i fix this?

Asked by 4 years ago
local SwingAnim = game.workspace.Animations.Swing
local Pluck = game.StarterPack.Pluck
function onTouched(Obj)
    local h = Obj.Parent:FindFirstChild("Humanoid")
    if h then
        h.Health = 0
    end
end

script.Parent.Touched:Connect(onTouched)

Pluck.Activated:Connect(function()
    print("Swing starts now")
end)
0
Make sure that you have activated the tool while testing. soccerstardance251 29 — 4y
0
yes i have activated it kaydengiurtino 2 — 4y
0
Make sure that the script is a local script soccerstardance251 29 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

So there are a few things wrong with this (what I assume to be) ServerScript. First, you're trying to reference the player's backpack with game.StarterPack. This is a problem because once your game runs everything in StarterPack is copied into the player's Backpack. So you won't really be making any changes to the current tool. To do this just put a LocalScript into the tool and write this:

local tool = script.Parent

tool.Equipped:Connect(function()
    tool.Activated:Connect(function()
        print("Swing starts now")
    end)
end)
0
tool.Equipped and toolActivated are the same thing. JesseSong 3916 — 4y
Ad

Answer this question