So, basically I’m just trying out a simple hunger system. The issue is coming in that my activated isn’t working.
local Toolie = script.Parent
Toolie.Activated:Connect(function()
if Debounce == true then return end
if Debounce == false then
Debounce = true
print("mhm")
RS.Eating:FireServer()
task.wait(9)
Debounce = false
end
end)
So, then what comes out of that is my question, I tried changing the name, making an independent variable for the tool, but it doesn’t really assist me in any way. The actual script works, as I did a task.wait(20) and the hunger went back up as if the character ate something in the last 20 seconds.
It’s located in the starterpack, so it’s very confusing to me as of why it’s not working.
Are you ever defining “debounce”? If not, it’s equal to nil, therefore none of your if-statements’ conditions are ever true. You don’t even need to check if debounce == false because you’re returning if it’s true, never which would result in never continuing the function if the debounce was true.
-- \\ Player-Related Variables //--
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local HUM = Character:WaitForChild("Humanoid")
local Humrp = Character:WaitForChild("HumanoidRootPart")
-- \\ Get-Service Variables // --
local UIS = game:GetService("UserInputService")
local RS = game:GetService("ReplicatedFirst")
-- \\ Server-Script-Variables // --
local SSS = game:GetService("ServerScriptService")
local RS = game:GetService("ReplicatedStorage")
local RunS = game:GetService("RunService")
local SP = game:GetService("StarterPack")
local CAS = game:GetService("ContextActionService")
local Debounce = false
--//Local Script
local tool = script.Parent
local debounce = false
local debounceHandler = function()
debounce = true
task.wait(9)
debounce = false
end
tool.Activated:Connect(function()
if not debounce then
task.spawn(debounceHandler)
game:GetService('ReplicatedStorage').Eating:FireServer()
end
end)
--//Server Script
game:GetService('ReplicatedStorage').Eating.OnServerEvent:Connect(function(player)
print('Event was fired from player '..player.Name)
end)
Did you trying printing as soon as the tool activates?
tool.Activated:Connect(function()
print("Activated")
if not debounce then
task.spawn(debounceHandler)
game:GetService('ReplicatedStorage').Eating:FireServer()
end
end)
If it didn’t print immediately after .Activated you should put a print right before .Activated to make sure you haven’t accidentally created some logic that will never reach it.
--//Local Script
local tool = script.Parent
local debounce = false
print("localtestingprior")
local debounceHandler = function()
debounce = true
task.wait(9)
debounce = false
end
print("testing")
tool.Activated:Connect(function()
if not debounce then
print("were we working before")
task.spawn(debounceHandler)
print("spawn")
game:GetService('ReplicatedStorage').Eating:FireServer()
print("we on?")
end
end)
It’ll only print anything outside of the .Activated. So even with this information I’m still confused on what the issue could be.
Ahh. Set ManualActivationOnly to false. When it’s true Activate will only fire when you call tool:Activate() in a script. It will ignore mouse input when that’s true.