My sword keeps dissapearing after I respawn. I have it in the starter pack and everything is working when I initially play however when I die and come back it dissapears and seems to be invisible in my hand but still does damage.
Here is the script currently inside of the sword.
I have tried changing things in the properties but nothing seemed to resolve it.
local Tool = script.Parent
local Handle = Tool:WaitForChild("Handle")
local Players = game:GetService("Players")
local Debris = game:GetService("Debris")
local Damage = 10 -- Single damage value
local Swing1Id = "rbxassetid://86592608326206" -- Left swing animation
local ComboSwingId = "rbxassetid://138614484845831" -- Combo swing animation
local Player, Character, Humanoid
local ToolEquipped = false
Tool.Enabled = true
local LastClickTime = 0.4
local DoubleClickCooldown = 0.2 -- Max time between clicks for a combo swing
local ComboCooldown = 0.7 -- Cooldown after a combo attack
local IsSwinging = false -- Tracks if the sword is currently swinging
local NextSwingIsCombo = false -- Tracks whether to play the combo swing next
function TagHumanoid(humanoid, player)
local Creator_Tag = Instance.new("ObjectValue")
Creator_Tag.Name = "creator"
Creator_Tag.Value = player
Debris:AddItem(Creator_Tag, 2)
Creator_Tag.Parent = humanoid
end
function UntagHumanoid(humanoid)
for _, v in pairs(humanoid:GetChildren()) do
if v:IsA("ObjectValue") and v.Name == "creator" then
v:Destroy()
end
end
end
function Blow(hit)
if not hit or not hit.Parent or not CheckIfAlive() or not ToolEquipped or not IsSwinging then
return
end
local character = hit.Parent
if character == Character then
return
end
local humanoid = character:FindFirstChildOfClass("Humanoid")
if not humanoid or humanoid.Health <= 0 then
return
end
local player = Players:GetPlayerFromCharacter(character)
if player and player == Player then
return
end
UntagHumanoid(humanoid)
TagHumanoid(humanoid, Player)
humanoid:TakeDamage(Damage)
end
function PlayAnimation(animationId)
if Humanoid and Humanoid.RigType == Enum.HumanoidRigType.R15 then
local anim = Instance.new("Animation")
anim.AnimationId = animationId
local track = Humanoid:LoadAnimation(anim)
track:Play()
return track.Length -- Return animation length for timing
end
return 0
end
function Attack()
local currentTime = tick()
-- Prevent attacking during cooldowns
if IsSwinging then
return
end
IsSwinging = true -- Mark as swinging
-- Determine which animation to play
local animationId
if NextSwingIsCombo then
animationId = ComboSwingId
else
animationId = Swing1Id
end
-- Play the chosen animation
local animDuration = PlayAnimation(animationId)
task.delay(animDuration, function()
IsSwinging = false -- Reset swinging after animation
end)
-- Toggle the flag for the next attack
NextSwingIsCombo = not NextSwingIsCombo
-- Cooldown after attack
task.delay(ComboCooldown, function()
Tool.Enabled = true
end)
end
Tool.Activated:Connect(function()
if not Tool.Enabled or not ToolEquipped or not CheckIfAlive() then
return
end
Tool.Enabled = false
Attack()
end)
function CheckIfAlive()
return Player and Player.Parent and Character and Character.Parent and Humanoid and Humanoid.Health > 0
end
function Equipped()
Character = Tool.Parent
Player = Players:GetPlayerFromCharacter(Character)
Humanoid = Character:FindFirstChildOfClass("Humanoid")
if not CheckIfAlive() then
return
end
ToolEquipped = true
end
function Unequipped()
ToolEquipped = false
end
Tool.Equipped:Connect(Equipped)
Tool.Unequipped:Connect(Unequipped)
Handle.Touched:Connect(Blow)
However this is how it looks after I respawn.