#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)
Try the tool.Unequipe:Connect()
I tried it it didnt work
let me send the code
This is the line of code im trying to tweak
but im not sure how to
do you know where it should go in the code?
i tried an and statement but it didnt work
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)
i tried it but it only prints the message
** You are now Level 1! **
why did you put entire UIS.inputbegan inside
I think HS:Attack() is what you need to put there
which piece of code should go inside?
oh i see
it works like a charm
however
the tool no longer works
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)
It works perfectly
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
you can put a script into the tool and listen for for Tool.Activated event
How shall i put that in?
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
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'
woah there pardner
okay so
- send information to module
- send information when tool is clicked/activated
- change variable in module
question, is the module on client or server and is it the same context as the tool is.
the module is inside a local script in starter pack
Like this
what is requiring it
or like
combat is the localscript
and hitboxsettings is the module
right?
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
okay
and this script is on the client i assume
also how long do you want it tobe active for
i want it to be on for 60 seconds
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
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
where should i put this
u should decide that for urself
I want to make the module able to receive the information that the tool has been clicked
require(module).activated = true idk maybe? i haven't seen ur module
the module script
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
is all this code yours? it seems a different quality from the other stuff u changed
I got some from a youtube tutorial
But the other parts is me
thats why its kind of hard to navigate through this code with full knowledge