hello, i am trying to make a sword skill that active when player dies, but my problem is my script got no error and it not working.
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(char)
local humanoid = char:WaitForChild("Humanoid")
script.Parent.Die.OnServerEvent:Connect(function()
local root = humanoid.HumanoidRootPart
if humanoid.Health <= 1 then
local die = game.ReplicatedStorage.SwordSkills.DieSkill:Clone()
die.Position = root.Position + CFrame.new(0, 5, 0)
die.Parent = game.Workspace
task.wait(7)
die:Destroy()
end
end)
end)
end)
local tool = script.Parent
local player = game.Players.LocalPlayer
local debounce = false
if player.Character.Humanoid.Health <= 1 and player.Character:FindFirstChild("FLGS") and debounce == false then
debounce = true
script.Parent.Die:FireServer()
task.wait(3)
debounce = false
end
https://developer.roblox.com/en-us/api-reference/event/Humanoid/Died
Use the Humanoid.Died event which is fired whenever a player dies, instead of if player.Character.Humanoid.Health <= 1
as seen in the 2nd script.
still not work,
here is my script after changed
local tool = script.Parent
local player = game.Players.LocalPlayer
local debounce = false
player.Character.Humanoid.Died:Connect(function()
if debounce == false then
if player.Character:FindFirstChild("FLGS") then
debounce = true
script.Parent.Die:FireServer()
task.wait(3)
debounce = false
end
end
end)
β SERVER SCRIPT β
local replStorage = game:GetService("ReplicatedStorage")
local dieEvent = replStorage:WaitForChild("DieEvent")
dieEvent.OnServerEvent:Connect(function(player)
local character = player.Character
local humanoid = character:WaitForChild("Humanoid")
local root = humanoid:WaitForChild("HumanoidRootPart")
local die = game.ReplicatedStorage.SwordSkills.DieSkill:Clone()
die.Position = root.Position + CFrame.new(0, 5, 0)
die.Parent = game.Workspace
task.wait(7)
die:Destroy()
end)
β LOCAL SCRIPT β
local replStorage = game:GetService("ReplicatedStorage")
local dieEvent = replStorage:WaitForChild("DieEvent")
local player = game.Players.LocalPlayer or game.Players.PlayerAdded:wait()
local character = player.Character or player.CharacterAdded:wait()
local humanoid = character:WaitForChild("Humanoid")
local debounce = false
humanoid.Died:Connect(function()
if debounce then
return
end
debounce = true
dieEvent:FireServer()
task.wait(3)
debounce = false
end)
Put a RemoteEvent instance named βDieEventβ inside the ReplicatedStorage folder.
1 Like