I’m unsure whats causing this as I did many checks to ensure it is the player who should be hitting it. The main idea im trying to achieve is that the stun effect will randomly play, and if its enabled and the player hits the boss, they will take damage.
local Debris = game:GetService("Debris")
local Boss = script.Parent
local Mover = Boss.Follow
local StunHighlight = Boss.StunFX
function StunFX(repeatCount)
for i=1,repeatCount do
local SoundClone = script.Stun:Clone()
SoundClone.Parent = workspace.Effects
SoundClone:Play()
SoundClone.Ended:Connect(function()
SoundClone:Destroy()
end)
StunHighlight.Enabled = true
task.wait(0.1)
StunHighlight.Enabled = false
task.wait(0.25)
end
end
local VulnerableFrame = false
StunHighlight.Changed:Connect(function()
if StunHighlight.Enabled == true then
Boss.PrimaryPart.Touched:Connect(function(hit)
local Player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
local Character = hit.Parent
local Humanoid = hit.Parent:FindFirstChild("Humanoid")
if Player then
if Player ~= nil then
if Humanoid:GetState(Enum.HumanoidStateType.Freefall) then
if not VulnerableFrame then
local Force = Instance.new("AngularVelocity", Boss.PrimaryPart)
Force.AngularVelocity = Vector3.new(500,50,0)
Debris:AddItem(Force, 0.25)
VulnerableFrame = true
Boss.Humanoid.Health -= 25
task.wait(5)
VulnerableFrame = false
end
end
end
end
end)
end
end)
while true do
task.wait(math.random(5,10))
StunFX(math.random(1,3))
end