Hello I am having issues with my Tool Script. Any feedback is very much appreciated!
What do you want to achieve?
Have you ever played Bee Swarm Simulator? How you can click and it swings your tool. But if you hold click it will continuously
use your tool.
What is the issue?
My issue is that sometimes when you click it initiates the loop and continues without end.
Tool Script:
local ReplicatedStorage = game.ReplicatedStorage
local Broadcasts = ReplicatedStorage.Broadcasts
local Modules = ReplicatedStorage.Modules
local Data = require(Modules.Data)
local Item = require(Modules.Item)
local Webhook = require(game.ReplicatedStorage.Modules.Webhook)
local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local Character = Player.Character
local Humanoid = Character.Humanoid
local Animator = Humanoid.Animator
local ToolDebounce = false
local Breakout = false
local ItemData = Item[script.Parent.Name]
if not ItemData then
local NewWebhook = Webhook:CreateWebhook()
local Embed = Webhook:CreateEmbed()
Embed:SetColor(Color3.new(1, 0.4, 0.45))
Embed:SetTitle("TOOL - MISSING DATA")
Embed:SetDescription(script.Parent.Name.." is missing tool data.")
Embed:SetFooter(Player.Name.." | "..Player.UserId.." | UTC TICK: "..os.time())
NewWebhook:AddEmbed(Embed)
Webhook:SendAsync(NewWebhook, "WEBHOOK")
end
local function Swinging(WaitOnStart)
task.spawn(function()
while true do
if Breakout then return end
Animator:LoadAnimation(script.Parent.Swing):Play()
print("Swing Tool")
game.ReplicatedStorage.Broadcasts.Events.SwingTool:FireServer()
task.wait(ItemData.Rate)
end
end)
end
task.spawn(function()
Mouse.Button1Down:Connect(function()
Swinging(false)
end)
end)
task.spawn(function()
Mouse.Button1Up:Connect(function()
Breakout = true
task.wait(ItemData.Rate)
Breakout = false
end)
end)
Providing Structure to how to properly do this would be incredibly AMAZING!!