hi guys, I was trying to create a code so that if the shot hit a glass material part, the sound of the impact would play. Idk why isnt working, anybody know why?
local isGlass = false
local glass = game.Workspace.Baseplate:FindFirstChild("Glass")
if glass then
local glassSize = glass.Size
local glassPosition = glass.Position
if rayResult.material == glass and (rayResult.position - glassPosition).Magnitude <= (glassSize.Magnitude / 2 + rayRadius) then
isGlass = true
end
end
local glassSoundEffect1 = game.Workspace.Sounds.MaterialBulletImpact.Glass.BulletGlass1
local glassSoundEffect2 = game.Workspace.Sounds.MaterialBulletImpact.Glass.BulletGlass2
local glassSoundEffect3 = game.Workspace.Sounds.MaterialBulletImpact.Glass.BulletGlass3
local glassSoundEffect4 = game.Workspace.Sounds.MaterialBulletImpact.Glass.BulletGlass4
local glassSoundEffect5 = game.Workspace.Sounds.MaterialBulletImpact.Glass.BulletGlass5
if isGlass then
local glassRandomNumber = math.random(1, 5)
if glassRandomNumber == 1 then
glassSoundEffect1:Play()
elseif glassRandomNumber == 2 then
glassSoundEffect2:Play()
elseif glassRandomNumber == 3 then
glassSoundEffect3:Play()
elseif glassRandomNumber == 4 then
glassSoundEffect4:Play()
elseif glassRandomNumber == 5 then
glassSoundEffect5:Play()
end
end
im using the roblox fps template btw
** You are now Level 1! **