Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why is the bot detecting itself?

Im trying to fire an event when the bot dies.With the name of the player in it so the script knows who killed the bot.Here is the script: P.S It is very important for me because otherwise the quest cant work,pls help. Im always getting the error "Monkey is not a valid member of Players" but why is it detecting itself,btw monkey is the bot.

Local:

local Humanoid = script.Parent.Humanoid
local delayy = false
local remote = game.ReplicatedStorage.Check2
script.Parent.HumanoidRootPart.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid")then
		local plr = game.Players[hit.Parent.Name] 
		elseif hit:FindFirstChild("PlayerName")then
		local plr = game.Players[hit.PlayerName.Value]
script.Parent:WaitForChild("Humanoid").Died:Connect(function()

	if delayy == false then
remote:FireAllClients(plr)
delayy = true
print("died")
wait(1)
delayy = false
end
end)
end
end)

1 answer

✓ Accepted answer

local Humanoid = script.Parent.Humanoid
local delayy = false
local remote = game.ReplicatedStorage.Check2
script.Parent.HumanoidRootPart.Touched:Connect(function(hit)
    hum = hit.Parent:FindFirstChild("Humanoid")
    local plr = game.Players:GetPlayerFromCharacter(hit.Parent)

    if plr then
        Humanoid.Died:Connect(function()
            if delayy == false then
                 remote:FireClient(plr)
                 delayy = true
                 print("died")
                 wait(1)
                delayy = false
             end
       end)
     end
end)

3 comments

0

Bout to eat with family. If that doesn’t work I’ll look over it again later sorry.

0

Bout to eat with family. If that doesn’t work I’ll look over it again later sorry.

0

Oh when the bot dies sorry! I’ll change it real quick

This discussion is preserved as it was. New answers, comments, and votes are closed.