I’m attempting to Create a Script for the Player to pick up Balls that’s spawn around the map, and throw them at players, Apon the collision Of the ball and the player, the Player gets flung in the opposite direction with extreme force.
Issue is, I’ve move my Ball Projectile Script to ServerScriptServices and It detects if the balls thrown by a RemoteEvent From the LocalScript in StarterCharacterScripts Firing it.
Once Detected by the Main Script it summons the projectile Ball Inside the a Folder called “ExistingBalls” In the Workspace with BodyVelocity in the Direction the Player is facing.
But the Main issue is that The Flinging Script Breaks due to before the Balls thrown, it cant Find the Ball in the Folder Therefore Breaking itself.
I’ve tried many different ways to fix this issue, but recently just came back to scripting after a few months of break, so i’m a bit rusty
What i’m trying to achieve is for the Flingscript to Wait until it Finds the Ball in the Folder in the workspace
Before Doing in the rest of its code, aswell as having it do this multiple times. (within testing the ball could only fling a player once before never flinging them again after Respawning the player)
If anyone has any advice, it’ll be greatly appreciated
-FlingingScript-
local debounce = false
--The Main Projectile Ball
local Balltest = workspace.ExistingBalls:WaitForChild("CometBall"):WaitForChild("HitBox")
--If Ball is Touched
Balltest.Touched:Connect(function(hit)
print("touched")
local Hit_Character = hit.Parent:FindFirstChild("Humanoid").Parent
if debounce == false then debounce = true
--All the Variables
local bv = Instance.new("BodyVelocity")
local offset = Vector3.new()
local IsRagdoll = (hit.Parent:WaitForChild("IsRagdoll"))
local ClonedImpact = game.ReplicatedStorage.Impact.Part:Clone()
local Particle1 = ClonedImpact.Debris
local Particle2 = ClonedImpact.Flash
local Particle3 = ClonedImpact.Flash2
local Particle4 = ClonedImpact.Shards
local Particle5 = ClonedImpact.Spinthings
local sound1 = ClonedImpact.Sound1
local sound2 = ClonedImpact.Sound2
local sound3 = ClonedImpact.Sound3
local sound4 = ClonedImpact.Sound4
local sounds = {sound1, sound2, sound3, sound4}
--Special Effects and Sounds
sounds[math.random(1, #sounds)]:Play()
ClonedImpact.Parent = workspace
ClonedImpact.CFrame = hit.Parent:WaitForChild("Torso").CFrame * CFrame.new(0,0,0)
Particle1:Emit(16)
Particle2:Emit(10)
Particle3:Emit(10)
Particle4:Emit(16)
Particle5:Emit(10)
--The Flinging Code + Ragdoll Activation
bv.Parent = (Hit_Character.Torso)
bv.MaxForce = Vector3.new(100000,100000,100000) -- can mess with this or the 80's
bv.Velocity = (Hit_Character.Head.CFrame.LookVector * -400)
+ (Hit_Character.Head.CFrame.UpVector * 100)
IsRagdoll.Value = true
--Destroying the BodyVelocity of the Player + Setting HP to 0
wait(0.01) bv:Destroy()
debounce = false
wait(3)
hit.Parent:WaitForChild("Humanoid").Health = 0
ClonedImpact:Destroy()
end wait(1)
end)
If you need more Detail, let me know