Have a script for a sword. Though line 38 is giving a bug error. Players.trueblockhead101.Backpack.Stick.Slash:38: attempt to index nil with ‘FindFirstChild’
Here’s the script.
local tool = script.Parent
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local InputService = game:GetService("UserInputService")
local InputType = Enum.UserInputType
local animation = nil
local slashAnimation = nil
tool.Equipped:Connect(function()
animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://7132227504"
slashAnimation = humanoid:LoadAnimation(animation)
end)
tool.Unequipped:Connect(function()
animation:Destroy()
slashAnimation = nil
end)
local debounce = false
InputService.InputBegan:Connect(function(input, processed)
if input.UserInputType == InputType.MouseButton1 and slashAnimation and not processed then
if debounce == false then
debounce = true
slashAnimation:Play()
local Connection
local tool = script.Parent
local function onTouch(partOther)
local humanOther = partOther.Parent:FindFirstChild("Humanoid")
if not humanOther then return end
if humanOther.Parent == tool then return end
humanOther:TakeDamage(5)
if humanOther.Health <= 0 then
player.leaderstats.Souls.Value = player.leaderstats.Souls.Value + 1
humanOther.Parent:Destroy()
end
end
Connection = tool:WaitForChild("Handle").Touched:Connect(onTouch)
slashAnimation.Stopped:Wait()
debounce = false
Connection:Disconnect()
wait(.2)
debounce = false
end
end
end)
1 Like
Could you share an rbxm file of the tool?
Because line 38 has nothing on it:
local tool = script.Parent --1
local player = game.Players.LocalPlayer --2
local character = player.Character or player.CharacterAdded:Wait() --3
local humanoid = character:WaitForChild("Humanoid") --4
--5
local InputService = game:GetService("UserInputService") --6
local InputType = Enum.UserInputType --7
--8
local animation = nil --9
local slashAnimation = nil --10
--11
tool.Equipped:Connect(function() --12
animation = Instance.new("Animation") --13
animation.AnimationId = "rbxassetid://7132227504" --14
slashAnimation = humanoid:LoadAnimation(animation) --15
end) --16
--17
tool.Unequipped:Connect(function() --18
animation:Destroy() --19
slashAnimation = nil --20
end) --21
--22
local debounce = false --23
InputService.InputBegan:Connect(function(input, processed) --24
if input.UserInputType == InputType.MouseButton1 and slashAnimation and not processed then --25
if debounce == false then --26
debounce = true --27
--28
slashAnimation:Play() --29
local Connection --30
local tool = script.Parent --31
--32
local function onTouch(partOther) --33
--34
local humanOther = partOther.Parent:FindFirstChild("Humanoid") --35
--36
if not humanOther then return end --37
-- this is line 38
if humanOther.Parent == tool then return end
humanOther:TakeDamage(5)
if humanOther.Health <= 0 then
player.leaderstats.Souls.Value = player.leaderstats.Souls.Value + 1
humanOther.Parent:Destroy()
end
end
Connection = tool:WaitForChild("Handle").Touched:Connect(onTouch)
slashAnimation.Stopped:Wait()
debounce = false
Connection:Disconnect()
wait(.2)
debounce = false
end
end
end)
If you’re not comfortable with giving your tool away to the public, you could either give it to me in private messages, or just not give it.
You can model if you don’t know how to make an rbxm file.
1 Like
Hello again.
local tool = script.Parent
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local InputService = game:GetService("UserInputService")
local InputType = Enum.UserInputType
local animation = nil
local slashAnimation = nil
tool.Equipped:Connect(function()
animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://7132227504"
slashAnimation = humanoid:LoadAnimation(animation)
end)
tool.Unequipped:Connect(function()
animation:Destroy()
slashAnimation = nil
end)
local debounce = false
InputService.InputBegan:Connect(function(input, processed)
if input.UserInputType == InputType.MouseButton1 and slashAnimation and not processed then
if debounce == false then
debounce = true
slashAnimation:Play()
local Connection
local tool = script.Parent
local function onTouch(partOther)
local humanOther = partOther.Parent:FindFirstChild("Humanoid") --line 38
if not humanOther then return end
if humanOther.Parent == tool then return end
humanOther:TakeDamage(5)
if humanOther.Health <= 0 then
player.leaderstats.Souls.Value = player.leaderstats.Souls.Value + 1
humanOther.Parent:Destroy()
end
end
Connection = tool:WaitForChild("Handle").Touched:Connect(onTouch)
slashAnimation.Stopped:Wait()
debounce = false
Connection:Disconnect()
wait(.2)
debounce = false
end
end
end)
Sorry I skipped lines at the start lol
1 Like
Huh, weird.
Could you provide a model of rbxm file of the tool? Last topic, I tried to recreate your tool so I could test the script, but it didn’t work, so I’d like to see how your tool functions. You can send the model / rbxm file to me in private messages, or just reply to this with a link / download.
Is the game R6 or R15, because the tool isn’t working, no errors nothing. Also
do you know that
tool.Activated:Connect(function()
end)
exists?
both r 15 and r6. And could you explain?
1 Like
Explain what? tool.Activated:Connect(function()
, or why I need to know why I need to know if it worked with R6 or R15?