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

How do you fix the module not working after the caller leaves?

When the caller leaves the module stops the code entirely. For example, if I were to do this in a module

-- The script that calls the module
local Player = game.Players.LocalPlayer
local EnemyPlayer = workspace.EnemyPlayer 
local Module = require(game.ReplicatedStorage.Module)
module.Call(EnemyPlayer)
--Module Call
EnemyPlayer.Humanoid:TakeDamage(20)
wait(20)
EnemyPlayer.Humanoid:TakeDamage(20)

If the Player were the one to call the module and leave between the wait time, the second damage wouldn't happen. How do I fix this?

1 comment

0

You could also use pcall(function() as that will keep the code running even if an error occurs.

1 answer

Well you can't damage a Player when they leave, but you can avoid the error by checking if the EnemyPlayer exists before damaging them.

if game.Players:FindFirstChild(EnemyPlayer.Name) then
	EnemyPlayer.Humanoid:TakeDamage(20)
end

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