Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Can't Call my global function?

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

3 comments

0

Take a close look at line 3. :P

0

just do repeat wait() until _G.PutToolOn _G.PutToolOn(Player,Hatchet,Bronze); also, fix line 3

0

It isn't working, fixed line 3. Same output as before

2 answers

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

1 comment

0

That doesn't work, bad syntax. I still don't know what is wrong with it?

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)
    

This discussion is preserved as it was. New answers, comments, and votes are closed.