I don’t know why this script is doing this, basically when you equip the tool and click it charges a bar, then you click again to release the ball.
THIS WORKS , however, after the first time not only does the throwing track not play, but the bar doesnt even charge when you click allowing you to change the power of your throw. It just instantly releases the ball. Why is it doing this?
EXAMPLE
I added prints where it’s not working and it goes to 4, then for some reason doesn’t print anything after that. Here’s the LocalScript, I’d send the Server one but I’m almost 100% sure that it’s not that.
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Tool = script.Parent.Parent
local GUI = Tool:WaitForChild("PowerGui")
if not Character.Parent then
Character.AncestryChanged:Wait()
end
local Root = Character:WaitForChild("HumanoidRootPart")
local Hum = Character:WaitForChild("Humanoid")
local Throw = script:WaitForChild("Throw")
local Mouse = Player:GetMouse()
Mouse.TargetFilter = workspace
local Head = Character:WaitForChild("Head")
local PB = GUI:WaitForChild("PowerBar")
local B = PB:WaitForChild("Bar")
local Line = B:WaitForChild("Line")
local Remotes = game.ReplicatedStorage:WaitForChild("Remotes")
local CM = Remotes:WaitForChild("LocalMechanics")
local power = 1
local MAX = 100
local releasedClick
local Hold = script:WaitForChild("HoldIdle")
local HoldTrack = Hum:LoadAnimation(Hold)
local PlayingHold
local equipped
function release()
equipped=nil
HoldTrack:Stop()
game.Debris:AddItem(GUI, 3)
releasedClick=true
local ThrowTrack = Hum:LoadAnimation(Throw)
ThrowTrack:Play()
local T
T = ThrowTrack:GetMarkerReachedSignal("Throw"):Connect(function()
Mouse.TargetFilter = workspace
local origin = Head.CFrame.p
local target = Mouse.Hit.p
CM:FireServer("Throw", {origin=origin, target=target, power=power})
T:Disconnect()
end)
end
local charging
function charge()
print'1'
charging=true
print'2'
while wait() do
print'3'
if power < MAX and not releasedClick then
print'4'
power = power + 2.5
else
print'5'
break
end
end
print'6'
if not released and not releasedClick then
print'7'
while wait() do
print'8'
if power - 5 <= 1 then
print'9'
power = 1
print'10'
released = true
print'11'
release()
print'12'
break
else
power = power - 10
end
end
end
end
Tool.Equipped:Connect(function()
releasedClick=nil
if not releasedClick and not released then
equipped=true
end
Mouse.TargetFilter = workspace
GUI.Parent = Player.PlayerGui
end)
Tool.Unequipped:Connect(function()
equipped=nil
GUI.Parent = Tool
end)
Mouse.Button1Down:Connect(function()
if equipped then
if not charging then
charge()
else
if not released then
release()
HoldTrack:Stop()
equipped=nil
end
end
end
end)
game:GetService("RunService").RenderStepped:Connect(function()
if equipped then
Line:TweenPosition(UDim2.new(power/MAX,0,.5,0),"Out", "Quad",.1,true)
if Hum.MoveDirection == Vector3.new(0,0,0) then
if not PlayingHold then
PlayingHold=true
HoldTrack:Play()
end
else
PlayingHold=nil
HoldTrack:Stop()
end
end
end)