I have a script that’s suppose to print “killed da enemy” every time an enemy is killed and it works fine the first time they die, but after that it stops working. I’ve tried redefining the enemyHumanoid 0.5 seconds after they’re killed but it doesn’t work (the humanoid always stays where it is in the studio’s workspace).
What happens:
https://gyazo.com/017bdd05af94438ec77b96ea1ba2e3a9
Script:
local platform = script.Parent
local ringTeleportPosition = script.Parent.Parent.PlayerSpawn.Position
local respawnPosition = Vector3.new(0, 0, 0)
local playerInRing = false
local Round1Event = game.ReplicatedStorage.Round1
local Round2Event = game.ReplicatedStorage.Round2
local Round3Event = game.ReplicatedStorage.Round3
local MatchFinishedEvent = game.ReplicatedStorage.MatchFinished
local enemiesFolder = script.Parent.Parent.Enemies
local enemyHumanoid = enemiesFolder["Alvin Kleid"]:FindFirstChild("Humanoid")
local hasRound1Started = false
local hasRound2Started = false
local hasRound3Started = false
local character = nil
local humanoid = nil
local player = nil
local function manipulatePlatformAndBeams(isVisible)
platform.BrickColor = isVisible and BrickColor.new("Bright red") or BrickColor.new("Mid gray")
for _, child in pairs(platform:GetChildren()) do
if child:IsA("Beam") then
child.Enabled = not isVisible
end
end
end
local function Rounds()
if hasRound1Started == true and hasRound2Started == true and hasRound3Started == true then
MatchFinishedEvent:FireClient(player)
playerInRing = false
manipulatePlatformAndBeams(false)
elseif hasRound1Started == true and hasRound2Started == true and hasRound3Started == false then
hasRound3Started = true
Round3Event:FireClient(player)
elseif hasRound1Started == true and hasRound2Started == false and hasRound3Started == false then
hasRound2Started = true
Round2Event:FireClient(player)
elseif hasRound1Started == false and hasRound2Started == false and hasRound3Started == false then
hasRound1Started = true
Round1Event:FireClient(player)
end
end
local function onPlatformTouched(hit)
character = hit.Parent
humanoid = character:FindFirstChild("Humanoid")
player = game.Players:GetPlayerFromCharacter(character)
if humanoid and player and not playerInRing then
playerInRing = true
Rounds()
local character = player.Character
if character then
character:SetPrimaryPartCFrame(CFrame.new(ringTeleportPosition))
character:WaitForChild("Humanoid").Died:Connect(function()
playerInRing = false
hasRound1Started = false
hasRound2Started = false
hasRound3Started = false
player:LoadCharacter()
end)
manipulatePlatformAndBeams(true)
end
end
end
enemyHumanoid.Died:Connect(function()
character:SetPrimaryPartCFrame(CFrame.new(ringTeleportPosition))
Rounds()
print("killed da enemy")
end)
platform.Touched:Connect(onPlatformTouched)