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

creator tag value is nil?

Asked by 7 years ago
Edited 7 years ago

I'm trying to make a tool that drops a boulder upon clicking, and I keep getting an error message from my leader board saying "attempt to index local "killer" (a nil value) ".

--function that inserts that boulder/creator tag
local tool = script.Parent
local boulder = script.BScript
local clickEvent = tool.ClickEvent
local clickEventConnection
local bCreator = tool.Parent.Parent.Name

local function createPart(location)
    local part = Instance.new("Part", game.Workspace)
    part.Name = "Boulder"
    part.Shape = "Ball"
    part.Size = Vector3.new(13,13,13)
    local mesh = Instance.new("FileMesh", part)
    mesh.MeshId = "http://www.roblox.com/asset/?id=1290033"
    mesh.TextureId = "http://www.roblox.com/asset/?id=1290030"
    mesh.Scale = Vector3.new(10, 10, 10)
    local bscript = boulder:Clone()
    bscript.Parent = part
    bscript.Disabled = false
    local creatorTag = Instance.new('ObjectValue', part)
    creatorTag.Value = bCreator
    creatorTag.Name = 'creator'
    part.CFrame = location
end
--Script that gets duplicated into the boulder

local boulder = script.Parent
local creatorTag = boulder:WaitForChild("creator")

local DebrisService = Game:GetService('Debris')

local function ApplyTags(target)
    while target:FindFirstChild('creator') do
        target.creator:Destroy()
    end

    local creatorTagClone = creatorTag:Clone()
    DebrisService:AddItem(creatorTagClone, 1.5)
    creatorTagClone.Parent = target
end


function onTouch(hit)
    local humanoid = hit.Parent:findFirstChild("Humanoid")
    if humanoid ~= nil then
        if hit.Parent:findFirstChild("Boulder Shield")== nil then
            humanoid.Health = humanoid.Health - 70
            ApplyTags(humanoid)
        end
    end
end
script.Parent.Touched:connect(onTouch)


wait(5)
script.Parent:Destroy()
0
Also, don't name anything "bCreator". That could be read as "a boolean value called creator". Same goes for "iCreator" (integer called creator), "fCreator" (float called creator), etc. Basically, avoid starting with a single lowercase letter. SwardGames 325 — 7y
0
Thanks for the tip! I'll fix that. Colby3292 5 — 7y

1 answer

Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

No formatting is better than bad formatting. But good formatting (the type ROBLOX provides itself) is better than no formatting.

Include formatting.

Also, include the complete error message. Knowing the script and line number is nice.

Anyway, the issue looks like it originates in a different script (the one which created the tag in the first place). It looks to me like it creates the tag and puts it in the projectile, but does not set its value.

EDIT: According to the code which creates the original tag, you are assigning the ObjectValue's value (which is, well, an object) to the player's name (which is a string). This would produce an error.

0
How would I fix that? Colby3292 5 — 7y
0
Change line 6 to local bCreator = tool.Parent.Parent --Also, change the name. It is confusing. SwardGames 325 — 7y
0
Thanks, it works! Colby3292 5 — 7y
Ad

Answer this question