I have encountered an "error". (It doesn't tell me anything in the output) On line 9 the If statement is getting ignored I think? And I have gone through the code and printed and stuff trying to figure out what the problem is but nothing. What it's supposed to happen is when the Punch Animation is played then the window should be able to break else if you just knock into it by accident nothing should happen but it still breaks if I knock into it. Why?
server script code:
local Glass = workspace.Glass_One
local RemoteEv = game.ReplicatedStorage.RemoteEV.BreakGlassHammer
local particle = Glass.ParticleEmitter
local Shatter = game.ReplicatedStorage.Glass.Shatter
local sound = Glass.Glass_Break
RemoteEv.OnServerEvent:Connect(function(player)
Glass.Touched:Connect(function(hit)
if player.Animations:FindFirstChild("PlayingPunchAnim") and
hit.Parent:FindFirstChild("RightHand") then
wait(0.1)
particle.Enabled = true
wait(0.2)
particle.Enabled = false
Shatter.Parent = workspace
Shatter.Anchored = true
player.Character.Humanoid.Health = player.Character.Humanoid.Health -100
player.PlayerGui.DeathScreenGlass.Enabled = true
Glass.Parent = game.ReplicatedStorage.Glass
for i = 1,1 do
sound:Play()
wait(1)
end
wait(70)
Shatter.Parent = game.ReplicatedStorage.Glass
Glass.Parent = workspace
else
end
end)

4 comments
You should write in more detail what you are trying to do what is happening and any other additional information you may have that can help.
The Variable 'Humanoid' is not defined.
Because the touched event has an arguement of hit, meaning whatever touches it will be defined when you call "Hit". If the right leg or left leg touches it, there is no "RightHand" child inside of "hit". I also recommend you use Debounce because the if statement will keep firing untill the player leaves the brick, firing multiple sounds from your glass break sound effect :Play() event.
I have put more detail to my question and how would i do this with somthing else exept hit?