Hello DevForum! Recently, I have been making my own dodgeball, which I have successfully made yesterday with the help of @Dev_Peashie and more researching. The only problem now is that if there are multiple dodgeballs inside of the game, none of the dodgeballs work. I am very confused because there are no errors and the print statements inside of my scripts print okay. Here are my scripts so far…
Script inside each dodgeball:
local equipped = script.Parent.Equipped
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
if equipped.Value == false then
equipped.Value = true
local character = hit.Parent
print("True")
script.Parent.Position = character["Right Arm"].Position
local ballweld = game.ServerStorage.Dodgeball:Clone()
ballweld.Part0 = character["Right Arm"]
ballweld.Part1 = script.Parent
ballweld.Parent = script.Parent
script.Parent.Parent = character
local anim = script.Parent.HoldAnimation
local anim2 = script.Parent.BallEndAnimation
local humanoid = character.Humanoid
local hold = humanoid:LoadAnimation(anim)
local endanim = humanoid:LoadAnimation(anim2)
hold:Play()
end
end
end)
Local script inside starter player scripts:
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
mouse.Button1Down:Connect(function()
game.ReplicatedStorage.Fire:FireServer(player, mouse.Hit.p)
end)
Server script in server script service:
game.ReplicatedStorage.Fire.OnServerEvent:Connect(function(player, mousepos)
if player.Character:FindFirstChild("Dodgeball") then
player.Character.Dodgeball.Dodgeball:Destroy()
player.Character.Dodgeball.BrickColor = BrickColor.new("White")
player.Character.Dodgeball:WaitForChild("PlayerFired").Value = player.Name
local anim = player.Character.Dodgeball.HoldAnimation
local humanoid = player.Character.Humanoid
local hold = humanoid:LoadAnimation(anim)
hold:Stop()
player.Character.Dodgeball.Parent = workspace
if game.Workspace.Dodgeball:WaitForChild("PlayerFired").Value == player.Name then
print("added")
local balltoapplyforce = game.Workspace.Dodgeball
local bodyvelocity = Instance.new("BodyVelocity", balltoapplyforce)
bodyvelocity.MaxForce = Vector3.new(5000,10000,5000)
bodyvelocity.Velocity = (player.Character.Head.CFrame.LookVector * 100)
local touchconn
touchconn = balltoapplyforce.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
if hit.Parent.Name ~= player.Name then
hit.Parent:BreakJoints()
balltoapplyforce.BrickColor = BrickColor.new("Really red")
if touchconn ~= nil then
touchconn:Disconnect()
bodyvelocity:Destroy()
balltoapplyforce.BrickColor = BrickColor.new("Really red")
print("Destroyed")
else
touchconn:Disconnect()
bodyvelocity:Destroy()
balltoapplyforce.BrickColor = BrickColor.new("Really red")
end
end
end
end)
wait(1)
if touchconn ~= nil then
touchconn:Disconnect()
bodyvelocity:Destroy()
balltoapplyforce.BrickColor = BrickColor.new("Really red")
print("Destroyed")
end
balltoapplyforce:WaitForChild("Equipped").Value = false
print("yes")
end
end
end)
Thank you for that. After putting in more print statements though, I still can’t find out the issue. Now, when one dodgeball is in a player’s hand, it doesn’t fire at all when the mouse clicks and the weld is just destroyed, but after you pick up the second one and click, the first dodgeball that didn’t get fired gets fired. I am so confused, but I will send my output with the printed statements from the scripts.
Server script in server script service:
game.ReplicatedStorage.Fire.OnServerEvent:Connect(function(player, mousepos)
if player.Character:FindFirstChild("Dodgeball") then
print("1")
player.Character.Dodgeball.Dodgeball:Destroy()
player.Character.Dodgeball.BrickColor = BrickColor.new("White")
player.Character.Dodgeball:WaitForChild("PlayerFired").Value = player.Name
local anim = player.Character.Dodgeball.HoldAnimation
local humanoid = player.Character.Humanoid
local hold = humanoid:LoadAnimation(anim)
hold:Stop()
player.Character.Dodgeball.Parent = workspace
if game.Workspace.Dodgeball:WaitForChild("PlayerFired").Value == player.Name then
print("2")
local balltoapplyforce = game.Workspace.Dodgeball
local bodyvelocity = Instance.new("BodyVelocity", balltoapplyforce)
bodyvelocity.MaxForce = Vector3.new(5000,10000,5000)
bodyvelocity.Velocity = (player.Character.Head.CFrame.LookVector * 100)
local touchconn
touchconn = balltoapplyforce.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
print("3")
if hit.Parent.Name ~= player.Name then
print("4")
hit.Parent:BreakJoints()
balltoapplyforce.BrickColor = BrickColor.new("Really red")
if touchconn ~= nil then
print("5")
touchconn:Disconnect()
bodyvelocity:Destroy()
balltoapplyforce.BrickColor = BrickColor.new("Really red")
print("Destroyed")
else
touchconn:Disconnect()
bodyvelocity:Destroy()
balltoapplyforce.BrickColor = BrickColor.new("Really red")
end
end
end
end)
wait(1)
if touchconn ~= nil then
print("6")
touchconn:Disconnect()
bodyvelocity:Destroy()
balltoapplyforce.BrickColor = BrickColor.new("Really red")
print("Destroyed")
end
balltoapplyforce:WaitForChild("Equipped").Value = false
print("yes")
end
end
end)
Script inside each dodgeball
local equipped = script.Parent.Equipped
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
print("7")
if hit.Parent.Humanoid.Health ~= 0 then
print("8")
if equipped.Value == false then
print("9")
equipped.Value = true
local character = hit.Parent
print("True")
script.Parent.Position = character["Right Arm"].Position
local ballweld = game.ServerStorage.Dodgeball:Clone()
ballweld.Part0 = character["Right Arm"]
ballweld.Part1 = script.Parent
ballweld.Parent = script.Parent
script.Parent.Parent = character
local anim = script.Parent.HoldAnimation
local anim2 = script.Parent.BallEndAnimation
local humanoid = character.Humanoid
local hold = humanoid:LoadAnimation(anim)
local endanim = humanoid:LoadAnimation(anim2)
hold:Play()
end
end
end
end)
Well after looking at your prints. You can see that the second if statement in the serverEvent wasn’t printing the first time. My guess is that you aren’t referencing the right dodge ball. Lets say there are 4 parts in workspace called “Dodgeball”. When you do “game.Workspace.Dodgeball” you are just randomly selecting one of those dodge balls. So you might be referencing a dodgeball which might have been thrown by a totally different player. So when your if statement checks if the Dodge ball thats randomly getting selected has the same “PlayerFired” value as the players name, it might be false.
What I suggest you do is locally reference and store the dodgeball that the player threw inside the connection and use that variable whenever you need to reference the dodgeball the player threw.
Example:
game.ReplicatedStorage.Fire.OnServerEvent:Connect(function(player, mousepos)
if player.Character:FindFirstChild("Dodgeball") then
local Dodgeball = player.Character:FindFirstChild("Dodgeball")
if Dodgeball then -- check if the dodgeball exist
-- examples of how your first 3 lines would look referencing the players dodge ball
Dodgeball.Dodgeball:Destroy()
Dodgeball.BrickColor = BrickColor.new("White")
Dodgeball:WaitForChild("PlayerFired").Value = player.Name
-- continue your logic here
end
end
end)
Thats my guess on what the issue is! Also note there may be typos.
Thank you so much for your reply @Ze_tsu! Now, the issue of not being able to use one of the balls while there are multiple is solved. The only problem now is that you can’t use the other ball. It appears that only one ball will work. The other ball, when equipped will stay equipped, not fire, stay white, and just stay in the workspace.
Here is my script:
game.ReplicatedStorage.Fire.OnServerEvent:Connect(function(player, mousepos)
if player.Character:FindFirstChild("Dodgeball") then
local dodgeball = player.Character:FindFirstChild("Dodgeball")
if dodgeball then
print("Ye")
dodgeball.Dodgeball:Destroy()
dodgeball.BrickColor = BrickColor.new("White")
dodgeball:WaitForChild("PlayerFired").Value = player.Name
local anim = dodgeball.HoldAnimation
local humanoid = player.Character.Humanoid
local hold = humanoid:LoadAnimation(anim)
hold:Stop()
dodgeball.Parent = workspace
if game.Workspace.Dodgeball:WaitForChild("PlayerFired").Value == player.Name then
print("added")
local balltoapplyforce = dodgeball
local bodyvelocity = Instance.new("BodyVelocity", balltoapplyforce)
bodyvelocity.MaxForce = Vector3.new(5000,10000,5000)
bodyvelocity.Velocity = (player.Character.Head.CFrame.LookVector * 100)
local touchconn
touchconn = balltoapplyforce.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
if hit.Parent.Name ~= player.Name then
hit.Parent:BreakJoints()
balltoapplyforce.BrickColor = BrickColor.new("Really red")
if touchconn ~= nil then
touchconn:Disconnect()
bodyvelocity:Destroy()
balltoapplyforce.BrickColor = BrickColor.new("Really red")
print("Destroyed")
else
touchconn:Disconnect()
bodyvelocity:Destroy()
balltoapplyforce.BrickColor = BrickColor.new("Really red")
end
end
end
end)
wait(1)
if touchconn ~= nil then
touchconn:Disconnect()
bodyvelocity:Destroy()
balltoapplyforce.BrickColor = BrickColor.new("Really red")
print("Destroyed")
end
balltoapplyforce:WaitForChild("Equipped").Value = false
print("yes")
end
end
end
end)