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

Can't Call my global function?

Asked by
Subete 0
10 years ago

Code:

_G.PutToolOn = function(plr,tooltoquip,class)
    if tostring(tooltoquip) == "Hatchet" then
        local arm = game.Workspace.tostring(plr)['Right Arm']
        local iten = game.Lighting:findFirstChild(tostring(class).."Hatchet"):clone()
        iten.Parent = game.Workspace
        local w1 = Instance.new("Weld",arm)
        w1.Part0 = arm
        w1.Part1 = iten.Handle
        w1.C0 = CFrame.new(0,-1,-.8) * CFrame.fromEulerAnglesXYZ(80,0,0)
    end
end

Output:

21:16:27.792 - _G.PutToolOn(Player1,Hatchet,Bronze):1: attempt to call field 'PutToolOn' (a nil value)

Called it in command bar with:

_G.PutToolOn(Player,Hatchet,Bronze)

The function is in a normal script in ServerScriptService

0
Take a close look at line 3. :P TheeDeathCaster 2368 — 10y
0
just do repeat wait() until _G.PutToolOn _G.PutToolOn(Player,Hatchet,Bronze); also, fix line 3 KOTwarrior 150 — 10y
0
It isn't working, fixed line 3. Same output as before Subete 0 — 10y

2 answers

Log in to vote
0
Answered by
M39a9am3R 3210 Moderation Voter Community Moderator
10 years ago
function _G.PutToolOn(plr,tooltoquip,class) --All I did was remove the = and moved the _G. tag.
    if tostring(tooltoquip) == "Hatchet" then
        local arm = game.Workspace.tostring(plr)['Right Arm']
        local iten = game.Lighting:findFirstChild(tostring(class).."Hatchet"):clone()
        iten.Parent = game.Workspace
        local w1 = Instance.new("Weld",arm)
        w1.Part0 = arm
        w1.Part1 = iten.Handle
        w1.C0 = CFrame.new(0,-1,-.8) * CFrame.fromEulerAnglesXYZ(80,0,0)
    end
end
0
That doesn't work, bad syntax. I still don't know what is wrong with it? Subete 0 — 10y
Ad
Log in to vote
0
Answered by 10 years ago

There was an error on line three. Also if this is just a utility function why not use a ModuleScript?

_G.PutToolOn = function(plr,tooltoquip,class)
    if tostring(tooltoquip) == "Hatchet" then
        local arm = game.Workspace[tostring(plr)]['Right Arm']
        local iten = game.Lighting:findFirstChild(tostring(class).."Hatchet"):clone()
        iten.Parent = game.Workspace
        local w1 = Instance.new("Weld",arm)
        w1.Part0 = arm
        w1.Part1 = iten.Handle
        w1.C0 = CFrame.new(0,-1,-.8) * CFrame.fromEulerAnglesXYZ(80,0,0)

Answer this question