Hello again! It seems you've used my advice, and I appreciate that!...However, you might not understand the proper approach to this:
local rep = game.ReplicatedStorage
local mouseDetection = rep.MouseDetection
local UIS = game:GetService("UserInputService")
local delayed = false
local delayTime = 0
local equipped = false
local falseCanHit = rep.CantHit
local tool = script.Parent
tool.Equipped:Connect(function()
equipped = true
end)
tool.Unequipped:Connect(function()
equipped = false
end)
UIS.InputBegan:Connect(function(input)
if delayed == false then
if equipped == true and input.UserInputType == Enum.UserInputType.MouseButton1 then
delayed = true
mouseDetection:FireServer()
if delayed == true then
task.wait(delayTime)
falseCanHit:FireServer()
delayed = false
end
end
end
end)
while true do
wait(2)
print(delayed)
end
Now, there's a lot of reasons why it won't work. For example: you done if delayed == false then. In reality, you should just do if not delayed then since not = the opposite/not true.
Same for if equipped ==... just do if equipped, because you're checking if it's true. This is a lifesaver if you wanna save time on coding. Also, keep input.UserInputType ==... the same. That doesn't need much changing.
delayTime is literally 0 seconds, so it will run instantly. and for the if delayed == true then line below mouseDetection:FireServer(), that's not needed either... Also if you want advice on how to do this you will need to be more specific with your answer, I am not getting clear signs on what to do. But, what I WILL do is:
local Rep = game:GetService("ReplicatedStorage")
local ToolActivated = Rep.ToolActivated
local Delayed = false
local DelayTime = 1.5
local Activated = false
local CantHit = Rep.CantHit
local Tool = script.Parent
Tool.Activated:Connect(function()
if Delayed then return end
Equipped = true
ToolActivated:FireServer()
task.wait(DelayTime)
CantHit:FireServer()
Delayed = false
end)
while task.wait(2) do
print(Delayed)
end
if Delayed then return end If you read my last post I made on your question, return end stops the script here if Delayed is true. returning, again, is returning a value. But return end = no value is being returned. So no excess values are being added so don't worry.
THEN we make Equipped true. Then we fire the ToolActivated to server and wait for DelayTime (1.5 seconds, also proud of you for using task.wait :D). Then we fire CantHit to server too. Then end the function there.
local Rep = game:GetService("ReplicatedStorage")
local ToolActivated = rep:WaitForChild("ToolActivated")
local CanHit = true
local db = false
local CantHit = rep:WaitForChild("CantHit")
local Tool = script.Parent
ToolActivated.OnServerEvent:Connect(function(player)
CanHit = true
print(canHit)
end)
cantHit.OnServerEvent:Connect(function(player, delayTime)
CanHit = false
end)
Most of the variables you made are not needed whatsoever. delayTime, delayed and notMoving are all not needed for this. for delayTime, it doesn't carry over from the LocalScript to THIS script. It's not how it works. And notMoving barely has a use here, so again NOT needed.
Again, I hope this helped you understand what you need to do, and if you're stuck on anything just ask me!
(Edit: I replaced the while task.wait loop to the local, simple mistake ;w;)
1 comment
What event does not / is supposed to wait before executing? falseCanHit will be executed after task.wait(0) which is defaulted to 0.025 seconds, mouseDetection will be executed instantly.