Hello Devforum! I need help once again with my power charging script that I am working on. If you did not already know, I am working on a soccer game with a shooting tool that allows the player to charge up power in order to apply force to a ball. It is almost complete, but there is just one very important aspect that is not working which is the ball hitting action. I want the force from the charge to be applied to the ball, but it is not working as planned. What I am currently doing, is getting the number the player stops on from charging, saving the value in a table, and then using that number to apply the same amount of force. There are no error messages, so I assume that there is something happening within the script that I did wrong. I just do not know where. Here is the full script in progress.
local userinputservice = game:GetService("UserInputService")
local powergui = script.Parent:WaitForChild("ShootingPower")
local player = game.Players.LocalPlayer
local equipped = false
local holdingclick = false
local powersave = {}
local powerint = script.Parent:WaitForChild("PowerInt")
local ball = game.Workspace:WaitForChild("Ball")
local debounce = false
script.Parent.Equipped:Connect(function()
equipped = true
print("True")
local guiclone = powergui:Clone()
print("Cloned")
guiclone.Parent = player.PlayerGui
end)
userinputservice.InputBegan:Connect(function(input, gameProcessedEvent)
if equipped then
if input.UserInputType == Enum.UserInputType.MouseButton1 then
holdingclick = true
local power = 0
local maxpower = 50
local textlabel = player.PlayerGui:FindFirstChild("ShootingPower").TextLabel
print("Holding click")
while holdingclick do
task.wait()
if power < maxpower and holdingclick == true then
power = power + 1
textlabel.Text = "Power: "..power
elseif power <= maxpower and holdingclick == false then
print("Not holding! Break loop!")
powerint.Value = power
table.insert(powersave, power)
print(powersave[1])
break
end
end
end
end
end)
userinputservice.InputEnded:Connect(function(input, gameProcessedEvent)
if equipped then
if input.UserInputType == Enum.UserInputType.MouseButton1 then
holdingclick = false
print("Click ended")
wait()
print(powersave[1])
table.remove(powersave, 1)
print("Removed")
local shootanim = script.Parent:WaitForChild("ShootAnim")
local loadanim = player.Character.Humanoid:LoadAnimation(shootanim)
loadanim:Play()
end
end
end)
ball.Touched:Connect(function(hit)
print("Ball was hit")
if equipped then
print("Tool equipped")
if not debounce then
debounce = true
if not holdingclick then
print("Click not held")
if powersave[1] then
print("O baby a triple")
if hit.Parent:FindFirstChild("Humanoid") then
local foundplayer = game.Players:GetPlayerFromCharacter(hit.Parent)
if foundplayer == player then
local humanoidrootpart = foundplayer.Character:FindFirstChild("HumanoidRootPart")
local direction = CFrame.lookAt(humanoidrootpart.Position, ball.Position).LookVector
if direction.magnitude < 0.01 then
return
end
local bvelocity = Instance.new("BodyVelocity")
local kickforce = powersave[1]
bvelocity.Parent = ball
bvelocity.MaxForce = Vector3.new(1,1,1) * math.huge
bvelocity.Velocity = (direction.Unit * kickforce) + Vector3.new(0, kickforce/1.05, 0)
wait(0.1)
bvelocity:Destroy()
print("Finished baby")
end
end
end
end
end
end
end)
script.Parent.Unequipped:Connect(function()
equipped = false
local guiclone = player.PlayerGui:FindFirstChild("ShootingPower")
guiclone:Destroy()
end)
If you need more information then I will be here, but I really need help. How would I go about making it so that the number stopped on becomes the amount of force applied to the ball?