Tool doesnt stop even though the sound ended

Hey, I’m having this REALLY bad issue here.
So basically; I made a tool keep going forward when you hold click but stop when you release mouse1 or the sound ends but even when the sound ends it just keeps on going.

Heres the tool I was making:
https://www.roblox.com/library/9366714228/Builder-Brothers-Pizza-Delivery

For some reason, it stops charging when the sound ends in studio, but not in-game. I’ve been using Kohls Admin gear command to give me the tool ingame.
If anyone can help, please and thank you.

local Services = {
	RunService = game:GetService("RunService"),
	TweenService = game:GetService("TweenService"),
	Players = game:GetService("Players"),
}

local Create = function(ty)
	return function(data)
		local obj = Instance.new(ty)
		for k, v in pairs(data) do
			if type(k) == 'number' then
				v.Parent = obj
			else
				obj[k] = v
			end
		end
		return obj
	end
end

local Tool = script.Parent

local Assets = Tool:WaitForChild("Assets",3)
local Configuration = Tool:WaitForChild("Configuration",3)

local Variables = {
	Active = false,
	Equipped = false,
	Character = nil,
	Player = nil,

	Arm = nil,
	OriginalC0 = nil,
	C0 = nil,

	GUI = nil,

	Force = Create("BodyVelocity"){
		MaxForce = Vector3.new(math.huge,0,math.huge)
	},

	ToolGrips = {
		Active = CFrame.new(-0.0330870152, -0.156805992, -0.00628089905, -6.14787609e-07, -1, -4.14440429e-08, -3.13040914e-07, 4.14442347e-08, -1, 1, -6.14787609e-07, -3.13040943e-07),
		Inactive = CFrame.new(-1.37223721, 0, -0.0062828064, 0, 0, -1, 0, 1, 0, 1, 0, 0),
	}
}

Tool.Activated:Connect(function()
	Variables.Active = true
end)

Tool.Deactivated:Connect(function()
	Variables.Active = false
end)

Tool.Equipped:Connect(function()
	Variables.Equipped = true
	Variables.Character = Tool.Parent
	Variables.Arm = Variables.Character:FindFirstChild("RightShoulder",true) or Variables.Character:FindFirstChild("Right Shoulder",true)
	Variables.Player = Services.Players:GetPlayerFromCharacter(Variables.Character)

	if Variables.GUI == nil then
		Variables.GUI = Assets.PizzaGUI:Clone()
	end
	Variables.GUI.Parent = Variables.Player.PlayerGui

	if Variables.OriginalC0 == nil and Variables.C0 == nil then
		Variables.OriginalC0 = Variables.Arm.C0
		Variables.C0 = Variables.OriginalC0 * CFrame.Angles(math.rad(90),math.rad(-15),0)
	end
end)

Tool.Equipped:Connect(function()
	Variables.Equipped = false
	if Variables.GUI ~= nil then
		Variables.GUI.Parent = nil
	end
end)

while task.wait() do
	if Variables.Equipped == true and Variables.Active == true and Variables.Character ~= nil and Tool.Enabled == true then
		Tool:WaitForChild("Handle",3).Charge.Playing = true
		Services.TweenService:Create(Tool,TweenInfo.new(0.25,Enum.EasingStyle.Back),{Grip = Variables.ToolGrips.Active}):Play()
		Services.TweenService:Create(Variables.Arm,TweenInfo.new(0.25,Enum.EasingStyle.Back),{C0 = Variables.C0}):Play()
		repeat 
			task.wait()
			if Variables.Character:FindFirstChild("HumanoidRootPart") == nil then break end
			if Tool.Enabled == false then break end
			if Tool:WaitForChild("Handle",3).Charge.IsPlaying == false then break end
			Variables.Force.Parent = Variables.Character:FindFirstChild("HumanoidRootPart")
			Variables.Force.Velocity = Variables.Character:FindFirstChild("HumanoidRootPart").CFrame.LookVector * Configuration:GetAttribute("Speed")
			local Percent = Tool:WaitForChild("Handle",3).Charge.TimePosition/Tool:WaitForChild("Handle",3).Charge.TimeLength
			local Decrease = 1 - Percent
			Configuration.Charge.Value = Configuration.Charge.MaxValue * 0.4 * Decrease
		until Variables.Active == false or Variables.Equipped == false or Variables.Character == nil or Tool.Enabled == false or Tool:WaitForChild("Handle",3).Charge.IsPlaying == false or Configuration.Charge.Value <= Configuration.Charge.MinValue

		Tool.Enabled = false
		Variables.Active = false
		Variables.GUI.Cooldown.Visible = true
		task.delay(Configuration:GetAttribute("Cooldown"),function()
			Tool:WaitForChild("Handle",3).Charge.TimePosition = 0
			Configuration.Charge.Value = Configuration.Charge.MaxValue
			Variables.GUI.Cooldown.Visible = false
			Tool.Enabled = true
		end)

		Services.TweenService:Create(Variables.Arm,TweenInfo.new(0.25,Enum.EasingStyle.Back),{C0 = Variables.OriginalC0}):Play()
		Variables.Force.Parent = nil
		Tool:WaitForChild("Handle",3).Charge.Playing = false
		Services.TweenService:Create(Tool,TweenInfo.new(0.25,Enum.EasingStyle.Back),{Grip = Variables.ToolGrips.Inactive}):Play()
	end
end

Show the script dude, no one can see the script

1 Like

The script is in the Master script of the tool model.

No one can access the contents of your game except you and anyone who is involved in developing your game (unless stolen in any means, albeit rare.) You have to provide things for us to inspect, such as screenshots, video clips, and code snippets.

I am kinda confused I thought I put the model on sale?
Anyways, just edited my post to have the code from the master script -_-

Oh, I initially thought you were linking a game. My bad, although it is usually better to show the code you were having troubles with right on the post, instead of having others take your asset(s), just to see the code. Alternatively, you can just upload the model directly to the DevForum.

Anyways, based on the model, the script works as expected (although I have to change the sound’s ID, because it failed to load for me.) Perhaps you have your Charge sound looped?

Also, in the script practices side of things, you continuously create Tweens every time the tool is activated, when you can just create them before the while loop, and play those Tweens instead. There’s also redundancy inside the repeat ... until loop, where you checked whether or not, let’s say x == true, and then break the function, when you already specified them in the until statement.