I want to make it so that when you miss an attack, a secondary sound is played. This isn’t functioning properly, and instead, it just makes no sound, it doesn’t print that you missed either. It’s as if that part of the script is completely ignored, even when the criteria of a humanoid being there isn’t true.
Does anyone have any feedback or any ideas I could try?
for i,v in pairs(Enemies) do
if v.Parent:FindFirstChild("Humanoid") and Hit == false then
print ("You've found a creature.")
v.Parent.Humanoid:TakeDamage(Damage)
local PunchSound = Instance.new("Sound",v)
PunchSound.SoundId = "http://www.roblox.com/asset/?id=5151139750"
PunchSound:Play()
Hit = true
print ("Humanoid took damage!")
else
local MissSound = Instance.new("Sound",Player.Character.Humanoid)
MissSound.SoundId = "http://www.roblox.com/asset/?id=5151139750"
MissSound:Play()
print ("You missed")
end
end
for some reason sound doesnt work whe you parent them to a part or something idk why but its kinda cuz i have put a sound instance in a part before and it worked but now it only works when you parent them to workspace,guess a bug?
So do you know how to make it spawn in a specific location?
It’s not just the sound that is not working, the whole Else part of that script just isn’t registering, like the Print function in it doesn’t print anything even when a humanoid isn’t caught in the region
-- Variables --
local Remote = game.ReplicatedStorage.Practice
local Activated = false
local Hit = false
-- Settings --
local Damage = 15
-- Script --
Remote.OnServerEvent:Connect(function(Player)
if Activated == false then
print ("Activated!")
local Pos = Player.Character.HumanoidRootPart.CFrame*CFrame.new(0,0,-3).p
local Size = Vector3.new(2,2,2)
local Hitbox = Region3.new(Pos-Size,Pos+Size)
print (Hitbox.Size, " | ", Hitbox.CFrame)
local Enemies = workspace:FindPartsInRegion3(Hitbox,Player.Character,20)
for i,v in pairs(Enemies) do
if v.Parent:FindFirstChild("Humanoid") and Hit == false then
print ("You've found a creature.")
v.Parent.Humanoid:TakeDamage(Damage)
local PunchSound = Instance.new("Sound",v)
PunchSound.SoundId = "http://www.roblox.com/asset/?id=5151139750"
PunchSound:Play()
Hit = true
print ("Humanoid took damage!")
else
local MissSound = Instance.new("Sound")
MissSound.Parent = Player.Character.Humanoid
MissSound.SoundId = "http://www.roblox.com/asset/?id=5151139750"
MissSound:Play()
print ("You missed")
end
end
Hit = false
wait (0.2)
else print ("On Cooldown!")
end
end)
Here’s the full script, it’s basically a region table
I figured out the error on my own, thank you for the feedback. For anyone that might be having an issue with a secondary function in the region table, it won’t actually run anything at all if the region table is empty. The reason it isn’t making a sound when you miss is because there’s no loop that its running through as there are no items in the table. I will search for a solution to this problem, Thank you!