Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

The dev console says line five is'nt working, why?

Asked by 7 years ago
Edited 7 years ago
local Tool = script.Parent
play = Tool.Parent.Parent
mouse = play:GetMouse()
char = play.Character
hum = char.Humanoid
root = char.HumanoidRootPart


local en = true

Tool.RemoteEvent.OnServerEvent:connect(function(play,mousehit)
    local a = hum:LoadAnimation(Tool.Throw)
    a:Play()
    root.Cframe = CFrame.new(root.Position,root.Position + Vector3.new(mousehit.lookVector.x,0,mousehit.lookVector,z))
    wait (.7)
    local fireball = Tool.Handle.clone()
    fireball.CFrame = Tool.Handle.CFrame
    local bv = Instance.new("BodyVelocity")
    bv.MaxForce = Vector3.new(1e8,1e8,1e8)
    bv.Velocity = mousehit.lookVector * 50
    bv.Parent = fireball
    fireball.CanCollide = false
    fireball.Parent = game.Workspace
    game.Debris:AddItem(fireball,4)
    local ten = true
    fireball.Touched:connect(function(hit)
        if not ten then return end
        ten = false
        local ehum = hit.Parent:findFirstChild("Humanoid")or hit.Parent.Parent:findFirstChild("Humanoid")
        if ehum and ehum ~= hum then
            ehum:TakeDamage(20)
        elseif hit.Anchored ==true and hit.CanCollide==true then
            for i=1, 30 do
                local part = fireball:clone()
                part.Size = Vector3.new(1,1,1)
                part.CFrame = fireball.CFrame
                --part.BodyVelocity.MaxForce = Vector3.new(1e8,1e8,1e8)
                part.ParticleEmitter.LockedToPart = false
                part.BodyVelocity.Velocity = Vector3.new(math.random(-30,30),math.random(-30,30),math.random(-30,30))
                game.Debris:AddItem(part,1)
            end 
        end

        wait()
        ten = true

    end)
    end)


Also says that line five "attempts to index global index"

2 answers

Log in to vote
1
Answered by
cabbler 1942 Moderation Voter
7 years ago

You can't assume that the player has a loaded character. Make good use of functions like WaitForChild.

local Tool = script.Parent
play = Tool.Parent.Parent
mouse = play:GetMouse()
char = play.Character or play.CharacterAdded:wait()
hum = char:WaitForChild("Humanoid")
root = char:WaitForChild("HumanoidRootPart")
0
When I replace that with the first six lines, it says line 11 has a error.. Accelital -7 — 7y
0
Wait for the event as well. cabbler 1942 — 7y
Ad
Log in to vote
0
Answered by 7 years ago

Try replacing the play, char and humanoid with this

local Player = game:GetService'Players'.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Human = Character:WaitForChild("Humanoid")

you have to that because the char dont load as soon as the script does

0
And you wanna use a local script for tools KinqAustinn 293 — 7y
0
Not always. OldPalHappy 1477 — 7y
0
Well true KinqAustinn 293 — 7y
0
still doesnt work Accelital -7 — 7y
0
Hmm KinqAustinn 293 — 7y

Answer this question