Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

tool script not working?

Asked by 8 years ago

ok so i have a tool script and when i click it once it calls the fire function but when i click it again it doesnt work.

local players = game.Players
local tool = script.Parent
repeat wait() until players.LocalPlayer and players.LocalPlayer.Character
local player = players.LocalPlayer
local character = player.Character
local humanoid = character:WaitForChild("Humanoid")
local debounce = false


tool.Activated:connect(function()
    if debounce then return end
    debounce = true
    local vote = Instance.new("Hint",game.Workspace)
    vote.Text = player.Name.. " has voted"
    game.Debris:AddItem(vote,5)
end)


1 answer

Log in to vote
1
Answered by
4Bros 550 Moderation Voter
8 years ago

Ok, your problem is that you forgot to set your debounce back to false after you clicked, since it stayed to true it would not execute the rest of your code. Remember to always check your debounces.

local players = game.Players
local tool = script.Parent
repeat wait() until players.LocalPlayer and players.LocalPlayer.Character
local player = players.LocalPlayer
local character = player.Character
local humanoid = character:WaitForChild("Humanoid")
local debounce = false


tool.Activated:connect(function()
    if debounce then return end
    debounce = true
    local vote = Instance.new("Hint",game.Workspace)
    vote.Text = player.Name.. " has voted"
    game.Debris:AddItem(vote,5)
    debounce = false -- You need to set your debounce back to false again
end)

Ad

Answer this question