i need help with an error, when making my projectile it keeps saying, 23:54:35.755 Argument 1 missing or nil, and i've tried to fix the problem many times but it wouldnt work.
script.Parent.RemoteEvent.OnServerEvent:Connect(function(player, character) local char = player.Character or player.CharacterAdded:Wait() local root = character:WaitForChild("HumanoidRootPart") local fbtime = 4 local MuseProjectile = game.ReplicatedStorage.Part:Clone() MuseProjectile.Parent = workspace MuseProjectile.CFrame = root.CFrame * CFrame.new (0,0,-2) game.Debris:AddItem(MuseProjectile, fbtime) local bodyvel = Instance.new("BodyVelocity") bodyvel.MaxForce = Vector3.new(1e8, 1e8,1e8) bodyvel.Velocity = root.CFrame.LookVector * 80 bodyvel.Parent = MuseProjectile local debounce = false MuseProjectile.Touched:Connect(function(hit) if hit.isDescendantOf(char) then return end if hit.Parent:IsA("Accoutrement") then hit = hit.Parent end local enemyhumanoid = hit.Parent:WaitForChild("Humanoid") local enemyroot = hit.Parent:WaitForChild("HumanoidRootPart") if enemyhumanoid and not debounce then debounce = true MuseProjectile:Destroy() local HitM = game.ReplicatedStorage.Fire:Clone() HitM.Parent = enemyroot spawn(function() wait(.5) HitM.Enabled = false wait(.6) HitM.Destroy() end) enemyhumanoid:TakeDamage(25) wait() debounce = false end end) end)
In line 17, you should use colon when using functions like Instance:IsDescendantOf()
script.Parent.RemoteEvent.OnServerEvent:Connect(function(player, character) local char = player.Character or player.CharacterAdded:Wait() local root = character:WaitForChild("HumanoidRootPart") local fbtime = 4 local MuseProjectile = game.ReplicatedStorage.Part:Clone() MuseProjectile.Parent = workspace MuseProjectile.CFrame = root.CFrame * CFrame.new (0,0,-2) game.Debris:AddItem(MuseProjectile, fbtime) local bodyvel = Instance.new("BodyVelocity") bodyvel.MaxForce = Vector3.new(1e8, 1e8,1e8) bodyvel.Velocity = root.CFrame.LookVector * 80 bodyvel.Parent = MuseProjectile local debounce = false MuseProjectile.Touched:Connect(function(hit) if hit:IsDescendantOf(char) then -- line that had the error return end if hit.Parent:IsA("Accoutrement") then hit = hit.Parent end local enemyhumanoid = hit.Parent:WaitForChild("Humanoid") local enemyroot = hit.Parent:WaitForChild("HumanoidRootPart") if enemyhumanoid and not debounce then debounce = true MuseProjectile:Destroy() local HitM = game.ReplicatedStorage.Fire:Clone() HitM.Parent = enemyroot task.spawn(function() task.wait(.5) HitM.Enabled = false task.wait(.6) HitM.Destroy() end) enemyhumanoid:TakeDamage(25) task.wait() debounce = false end end) end)
If you are using Instance.IsDescendantOf(), you have to specify the instance itself, like
--These two are the same Instance.IsDescendantOf(Instance, char) Instance:IsDescendantOf(char)
it automatically passes itself, useful for object-oriented programming