#Do something when tool gets equipt

1 messages · Page 1 of 1 (latest)

dense sandal
#

Hey I just want that when you equip a tool that a script gets enabled but it just does nothing can someone help me there?

local Bat = game.StarterPack.Bat
local BatScript = script.Parent["Baseball Attack script"]
local longsword = game.StarterPack.Longsword
local longswordScript = script.Parent["Longsword Attack script"]
local WarHammer = game.StarterPack["War Hammer"]
local WarHammerScript = script.Parent["War Hammer Attack script"]

Bat.Equipped:Connect(function()
    print("Equip baseballbat")
    BatScript.Enabled= true
end)

longsword.Equipped:Connect(function()
    print("Equip baseballbat")
    longswordScript.Enabled= true
end)

WarHammer.Equipped:Connect(function()
    print("Equip baseballbat")
    WarHammerScript.Enabled= true
end)```
next grail
#

why would you even need to enable a script? also is this done in the server or in the client?

dense sandal
#

client

dense sandal
# next grail why would you even need to enable a script? also is this done in the server or i...

I just anable a script that like wait I can just send it:

local rs = game:GetService("ReplicatedStorage")

local remoteHit = game.ReplicatedStorage.Events.Hit

local events = rs:WaitForChild("Events")
local hitboxEvent = events:WaitForChild("Hitbox")

local plr = game.Players.LocalPlayer
local charakter = plr.Character or plr.CharacterAdded:Wait()
local hum = charakter:WaitForChild("Humanoid")
local animator = hum:WaitForChild("Animator")

local leftpunch = animator:LoadAnimation(script:WaitForChild("Leftpunch"))
local rightpunch = animator:LoadAnimation(script:WaitForChild("Rightpunch"))
local finalpunch = animator:LoadAnimation(script:WaitForChild("Finalpunch"))

local currentPunch = 0
local lastpunch = 0

local damage = 44
local attacktime = 1.7

local Hitsound = game.Workspace.Sounds.Hitmarker
local Fleshsound = game.Workspace.Sounds.Flesh
local Bongsound = game.Workspace.Sounds.Bong

local debounce = false```
#

that was the first half

next grail
#

then of course it wont activate

dense sandal
#
local function punch()
    if debounce then return end
    if tick() - lastpunch > 2.5 then
        currentPunch = 0
    end
    
    debounce = true
    if currentPunch == 0 then
        rightpunch:Play()
        wait(0.2)
        hitboxEvent:FireServer(Vector3.new(8,3,5), Vector3.new(2), damage, 0.3)
        task.wait(attacktime)
        debounce = false
    elseif currentPunch == 1 then
        leftpunch:Play()
        wait(0.2)
        hitboxEvent:FireServer(Vector3.new(8,3,5), Vector3.new(2), damage, 0.3)
        task.wait(attacktime)
        debounce =false
    elseif currentPunch == 2 then
        finalpunch:Play()
        wait(0.3)
        hitboxEvent:FireServer(Vector3.new(3,7,7), Vector3.new(2), damage, 0.3)
        task.wait(attacktime)
        debounce = false
    end
    
    print(currentPunch)
    
    if currentPunch == 2 then 
        currentPunch = 0
    else
        currentPunch += 1
    end
    lastpunch = tick()
end

cas:BindAction("Punch", punch, true, Enum.UserInputType.MouseButton1)


remoteHit.OnClientEvent:Connect(function()
    Hitsound:Play()
    Fleshsound:Play()
    Bongsound:Play()
end)```
dense sandal
next grail
#

are the script that you are trying to enable server scripts?

dense sandal
#

no

dense sandal
next grail
#

does it print?

#

"Equip baseballbat" ect..

dense sandal
next grail
#

try to print the items?

#

to see if they are nil or they are actually something?

dense sandal
next grail
#
local Bat = game.StarterPack.Bat
local BatScript = script.Parent["Baseball Attack script"]
local longsword = game.StarterPack.Longsword
local longswordScript = script.Parent["Longsword Attack script"]
local WarHammer = game.StarterPack["War Hammer"]
local WarHammerScript = script.Parent["War Hammer Attack script"]

print(Bat, longsword, WarHammer)

Bat.Equipped:Connect(function()
    print("Equip baseballbat")
    BatScript.Enabled= true
end)

longsword.Equipped:Connect(function()
    print("Equip baseballbat")
    longswordScript.Enabled= true
end)

WarHammer.Equipped:Connect(function()
    print("Equip baseballbat")
    WarHammerScript.Enabled= true
end)
dense sandal
#

it prints that

next grail
#

have you tried to search on roblox dev hub if someone else was experiencing something like this too?

dense sandal
#

no not yet but I can try that

next grail
#

u can try i found most of my answers there

dense sandal
next grail
#

also does it have a handle part?

dense sandal
#

yes the tool workes fine

dense sandal
next grail
#

so you have it in your backpack and u can equip it but the event its not firing

next grail
#

where did u put it