Hi, I'm trying to make a fire sword and when it it activated on the second time, it will make the opponent burn. This is the the burning script in the firesword tool:
01 | local cool = false |
02 | script.Parent.Touched:Connect( function (hit) |
03 | if hit.Parent:FindFirstChild( "Humanoid" ) and cool = = false and hit.Parent ~ = script.Parent.Parent.Parent then |
04 | if hit.Parent.Humanoid.Health > 0 then |
05 | cool = true |
06 | if game.ServerStorage:FindFirstChild( "Burn" ) then |
07 | local burn = game.ServerStorage.Burn:Clone() |
08 | burn.Parent = hit |
09 | burn.Disabled = false |
10 | if burn ~ = nil then |
11 | wait() |
12 | if hit.Parent.Humanoid.Health = = 0 then |
13 | local name = game.Players:GetPlayerFromCharacter(script.Parent.Parent.Parent) |
14 | if name:FindFirstChild( "leaderstats" ) then |
15 | name.leaderstats.Kills.Value = name.leaderstats.Kills.Value + 1 |
This will duplicate a burning script in my ServerStorage and send it to the hit part. here is the script:
01 | while script ~ = nil do |
02 | wait( 0.1 ) |
03 | local check = script.Parent.Parent:FindFirstChild( "Humanoid" ) -- 'Attempt to index nil with Parent 'error here |
04 | if check then |
05 | if script.Parent.Parent.Humanoid.Health > 0 then |
06 | cool = true |
07 | local wa = Instance.new( "Fire" ) |
08 | wa.Parent = script.Parent |
09 | for i = 1 , 5 do |
10 | script.Parent.Parent.Humanoid.Health = script.Parent.Parent.Humanoid.Health - 10 |
11 | wait( 1 ) |
12 | end |
13 | wa:Destroy() |
14 | script:Destroy() |
15 | cool = false |
16 | end |
17 | end |
18 | end |
Please help me fix this error. Thank you!
The problem is that it can't find the parent of the game.
script.Parent = ServerStorage script.Parent.Parent = game script.Parent.Parent.Parent = nil
And you're also trying to find the player's humanoid inside server storage, which humanoid is not one of server storage children.
Fortunately, we can use the data from the first script to get the player's humanoid using remote events.
No changes need to be made except pasting the script.
First code:
01 | local remoteevent = Instance.new( "RemoteEvent" , game.ReplicatedStorage) |
02 | remoteevent.Name = "BurnEvent" |
03 | local cool = false |
04 | script.Parent.Touched:Connect( |
05 | function (hit) |
06 | if hit.Parent:FindFirstChild( "Humanoid" ) and cool = = false and hit.Parent ~ = script.Parent.Parent.Parent then |
07 | if hit.Parent.Humanoid.Health > 0 then |
08 | cool = true |
09 | if game.ServerStorage:FindFirstChild( "Burn" ) then |
10 | local burn = game.ServerStorage.Burn:Clone() |
11 | burn.Parent = hit |
12 | burn.Disabled = false |
13 | if burn ~ = nil then |
14 | wait() |
15 | if hit.Parent.Humanoid.Health = = 0 then |
second code
01 | local remoteevent = game.ReplicatedStorage.BurnEvent |
02 | remoteevent:OnServerEvent(hit) |
03 | while script ~ = nil do |
04 | wait( 0.1 ) |
05 | local check = hit.Parent:FindFirstChild( "Humanoid" ) |
06 | if check then |
07 | if hit.Parent:FindFirstChild( "Humanoid" ).Health > 0 then |
08 | cool = true |
09 | local wa = Instance.new( "Fire" ) |
10 | wa.Parent = script.Parent |
11 | for i = 1 , 5 do |
12 | hit.Parent:FindFirstChild( "Humanoid" ).Health = hit.Parent:FindFirstChild( "Humanoid" ).Health - 10 |
13 | wait( 1 ) |
14 | end |
15 | wa:Destroy() |
16 | script:Destroy() |
17 | cool = false |
18 | end |
19 | end |
20 | end |