My script doesn't work but i don't know why it just says "index field "Character" (a nil value)" Heres the script that isnt working:
player = game.Players.LocalPlayer HumanoidRootPart = player.Character:WaitForChild("HumanoidRootPart") Mouse = player:GetMouse() destroyTime = 6
and heres the rest of the script:
velocity = 90 key = "r" Cooldown = 5 Material = "Smooth" Color = "Bright yellow" MaxSize = 2 Damage = 10
enable = true
Mouse.KeyDown:connect(function(keyI) keyI = keyI:lower() if keyI == key and enable == true then enable = false fireball = Instance.new("Part",game.Workspace) fireball.Name = "FireBall" game.Debris:AddItem(fireball,destroyTime) fireball.CanCollide = false fireball.Shape = "Ball" fireball.Touched:connect(DoDamage) fireball.Transparency = 0.010 fireball.Anchored = true fireball.TopSurface = Material fireball.BottomSurface = Material fireball.CFrame = HumanoidRootPart.CFrameCFrame.new(fireball.Position.X,fireball.Position.Y,fireball.Position.Z-5) fireball.BrickColor = BrickColor.new(Color) local fire = Instance.new("Fire",fireball) fire.Heat = 10 fire.Size = 30 local bv = Instance.new("BodyVelocity",fireball) bv.MaxForce = Vector3.new(math.huge,math.huge,math.huge) bv.Velocity = HumanoidRootPart.CFrame.lookVectorvelocity end end)
Mouse.KeyUp:connect(function(keyI) keyI = keyI:lower() if keyI == key and enable == false then fireball.Anchored = false wait(Cooldown) enable = true end end)
function DoDamage (part) if part.Parent.Humanoid and part.Parent.Name ~= player.Name then print("entrei") part.Parent.Humanoid.Health = part.Parent.Humanoid.Health - Damage; fireball:Destroy() end end
The error means that the character of the player is not spawned. You can add a check to prevent errors unless the character has spawned
if player.Character ~= nil then -- do stuff end