As the title says, I’m having problems with my sword tool.
For some reason, it overrides other scripts that are not part of its code.
For example, a respawn code for an NPC or Enemy, the NPC or Enemy will not respawn, if the respawn code is not part of the sword’s Local Script, I am asking how I can solve this before in the future, this causes more problems . Thanks.
local Tool = script.Parent
local Handle = Tool:FindFirstChild("Handle")
local SwordStatus = Tool:FindFirstChild("SwordStatus")
local StatusModule = require(SwordStatus)
local PlayerService = game:GetService("Players")
local LocalPlayer = PlayerService.LocalPlayer
local AniamtionsTable = StatusModule.AnimationTable
local SoundEffectTable = StatusModule.SoundeffectTable
local SoundEffect = Handle:FindFirstChild("SoundEffect")
local IsAttacking = false
local Debounce = false
Tool.Activated:Connect(function()
local RandomIndex = math.random(1, #SoundEffectTable)
local RandomSound = SoundEffectTable[RandomIndex]
SoundEffect.SoundId = RandomSound
SoundEffect:Play()
end)
Tool.Activated:Connect(function()
IsAttacking = true
task.wait(StatusModule.Damage)
Debounce = false
IsAttacking = false
end)
Handle.Touched:Connect(function(Hit)
local EnemyHumanoid = StatusModule.HumanoidToDamage
local SwordDamage = StatusModule.Damage
local SwordCooldown = StatusModule.Cooldown
if IsAttacking and Hit.Parent:WaitForChild(EnemyHumanoid) and Hit.Parent:WaitForChild(EnemyHumanoid):IsA("Humanoid") then
if not Debounce then
Debounce = true
Hit.Parent:FindFirstChild(EnemyHumanoid):TakeDamage(SwordDamage)
task.wait(SwordCooldown)
Debounce = false
if Hit.Parent:FindFirstChild(EnemyHumanoid).Health <= 0 and Hit.Parent:FindFirstChild("HumanoidRootPart") then
Hit.Parent.HumanoidRootPart:Destroy()
end
end
end
end)
I dont think a script can do that without doing some crazy stuff with setenv or lagging out the game immensely, neither of which I can see your script doing. Id have to guess its just a coincidence. Make sure that your respawn scripts and things are set up correctly (they’re server scripts or local scripts as appropriate, parented to the right things, descendents of things that will actually let it run, etc)
In my Enemy, there is a chase code, that if the players defeats the Enemy, the HumanoidRootPart still following the player, which makes it collides with the player, and after some time, the dead body of the Enemy just teleports over the player. i solved that by putting:
if Hit.Parent:FindFirstChild(EnemyHumanoid).Health <= 0 and Hit.Parent:FindFirstChild("HumanoidRootPart") then
Hit.Parent.HumanoidRootPart:Destroy()
end
On the script, and i tried to make a respawn script (By the way, it is a generic respawn script) in my Enemy, and, even if the Humanoid Die, the respawn just get useless and the Enemy never respawns. The only way i found for that, is by putting the respawn script inside the SwordHandler, but still, it has much errors (Like it respawns, but the other scripts becomes useless).
How do i know that? I tried putting the same Enemy (With the scripts inside), With a Classic sword and the sword that i am using without these “Problem solvers” inside the sword.
On the Classic sword, it works normal, the HumanoidRootPart don’t collide with the player and works decent, the respawning script too. It respawns the Enemy, with every script working fine.
But in the other sword, it just does the errors i mentioned before. Thats all.
(Also sorry for the reply delay, i was at school).