#How do I make it so when I click to use a tool the script for a punch doesn't activate

98 messages · Page 1 of 1 (latest)

stiff cargo
#

Im trying to make it so when I used a tool, the animation for the punch or the script itself doesn't turn on, cancelling the animation or usage for the tool itself

sick hornet
#

Try the tool.Unequipe:Connect()

stiff cargo
#

let me send the code

#

This is the line of code im trying to tweak

#

but im not sure how to

sick hornet
#

It's uh Unequipped:Connect()

#

Hmmm

stiff cargo
#

i tried an and statement but it didnt work

sick hornet
#

If your using a tool it should go at the end.

#

I will help you later im at work.

weak gorge
# stiff cargo Im trying to make it so when I used a tool, the animation for the punch or the s...

try this code:

local ContextActionService = game:GetService("ContextActionService")
local Players = game:GetService("Players")
local Player = Players.LocalPlayer

local ACTION_NAME = "Punch"

local function OnClick(ActionName, InputState, InputObject)
    if ActionName ~= ACTION_NAME then return end -- this line is actually useless
    if InputState ~= Enum.UserInputState.Begin then return end
    local Character = Player.Character
    if not Character then return end
    local Tool = Character:FindFirstChildOfClass("Tool")
    if Tool then return end
    print("MouseButton1 clicked with no tool equipped")
    -- your punch code goes here
end

ContextActionService:BindAction(ACTION_NAME, OnClick, false, Enum.UserInputType.MouseButton1)
stiff cargo
ebon gateBOT
#

studio** You are now Level 1! **studio

stiff cargo
#

and whenever i try to punch it no longer works

#

the tool also no longer works

weak gorge
#

why did you put entire UIS.inputbegan inside

#

I think HS:Attack() is what you need to put there

stiff cargo
#

oh i see

#

it works like a charm

#

however

#

the tool no longer works

weak gorge
#

oh, I didnt have enough expirience with tools to know that would happen
I edited the script. now it will work for you altho its definitely not the best solution:

local ContextActionService = game:GetService("ContextActionService")
local Players = game:GetService("Players")

local ACTION_NAME = "Punch"

local function OnClick(ActionName, InputState, InputObject)
    if ActionName ~= ACTION_NAME then return end -- this line is actually useless
    if InputState ~= Enum.UserInputState.Begin then return end
    local Player = Players.LocalPlayer
    local Character = Player.Character
    if not Character then return end
    local Tool = Character:FindFirstChildOfClass("Tool")
    if Tool then
        Tool:Activate() -- lol
        return
    end
    print("MouseButton1 clicked with no tool equipped")
    HS:Attack()
end

ContextActionService:BindAction(ACTION_NAME, OnClick, false, Enum.UserInputType.MouseButton1)
stiff cargo
#

Thank you so much

#

I also got another question

#

I want to make a remote event in my module script

#

This is how it looks like

#

it shows the damage

#

the first paragraph of code is basically the basic damage for the punches

#

the second paragraph is for a different version (once the tool has been used)

#

So im trying to find out how to make my tool tell the module that it has been activated

#

so that the code can run through the second paragraph instead of the first if that makes sense

weak gorge
#

you can put a script into the tool and listen for for Tool.Activated event

stiff cargo
#

this is the main part of the tool script

#

where it does the remote event

#

**local Tool = script.Parent
local Cooldown = false
local active = false
local CDTime = 80
local WalkSpeedBuff = 0
local sound = Instance.new("Sound")
sound.SoundId = "rbxassetid://7278163473"
sound.Parent = workspace

sound.TimePosition = 0.6

Tool.RemoteEvent.OnServerEvent:Connect(function(plr)
if Cooldown then return end

spawn(function()
active = true
Cooldown = true
wait(CDTime)
Cooldown = false 

end)**

#

Or should I put the script inside of the module

visual grove
stiff cargo
# visual grove

hey do you know what I should do to send information to my module that a tool when clicked has been activated so it can activate a local variable I made called 'active'

visual grove
#

woah there pardner

#

okay so

  1. send information to module
  2. send information when tool is clicked/activated
  3. change variable in module

question, is the module on client or server and is it the same context as the tool is.

stiff cargo
#

Like this

visual grove
#

what is requiring it

#

or like

#

combat is the localscript

#

and hitboxsettings is the module

#

right?

stiff cargo
#

So combat is what fires the event

#

it fires an event once the left mouse button is pressed

#

and the module basically puts the attacks together

#

since there are multiple hits that total up to 5

#

but im trying to find out how to amplify the damage script for a certain amount of time when the tool is pressed

#

the damage is also in the module here

#

the paragraph at the top is for when the tool isnt active

#

and the bottom is for when the tool is active

#

so everything works perfectly so far

#

but

#

when I use my tool, i want the local variable 'active' to become true

#

so the second paragraph is used instead of the first

#

until the time is over so it becomes false again

visual grove
#

okay

#

and this script is on the client i assume

#

also how long do you want it tobe active for

stiff cargo
#

so basically i alrady made a script for the tool so that it has a cooldown for 80 seconds after it has been active for 60 seconds

#

so initially its on for 60 seconds

#

then theres a 20 second cooldown until it can be used agian

visual grove
#

hmm alright

#

i would do something like

#

timeCanUse = os.time() + 60

and then you can do like

if os.time() > timeCanUse then
  -- can use
end 
visual grove
#

u should decide that for urself

stiff cargo
visual grove
#

require(module).activated = true idk maybe? i haven't seen ur module

visual grove
#

make it apart of the module

#

so HitboxSettings.active = false

#

instead of a local variable

#

then you can just edit it from wherever you need to

#

or just add it in .new

stiff cargo
#

So change it like this?

visual grove
#

is all this code yours? it seems a different quality from the other stuff u changed

stiff cargo
#

But the other parts is me

#

thats why its kind of hard to navigate through this code with full knowledge