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

How do you call a function?

Here is the script.

bin = script.Parent
move = script.Parent.Parent.Parent

function Click(Player)
	if script.Parent.Parent.Parent.Parent.GunSelector.Value == "M4" then
		game.Lighting.M4:Clone().Parent = game.Players.LocalPlayer.Backpack
		
		local player = game.Players.LocalPlayer
		local character = player.Character
		local tool = player.Backpack.M4
		
		local function equip(tool)
    			tool.Parent = character
		end
		
		tool.Equipped:connection(equip)
		-- ^ This won't equip it...
		game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false)
		move:Destroy()
print("Entered")	
end


bin.MouseButton1Click:connect(Click)

3 comments

0

tool.Equipped:connect(equip) but btw there's more stuff wrong with your script I believe

0

I'll edit it so I can be able to put the entire code

0

@DarwinYork

1 answer

Problem MouseButton1Click is not defined by a tool, this is defined by a mouse object which can be created when selected.

Solution

bin = script.Parent
move = script.Parent.Parent.Parent

function Click(Player)
    if script.Parent.Parent.Parent.Parent.GunSelector.Value == "M4" then
        game.Lighting.M4:Clone().Parent = game.Players.LocalPlayer.Backpack

        local player = game.Players.LocalPlayer
        local character = player.Character
        local tool = player.Backpack.M4

        local function equip(tool)
                tool.Parent = character
        end

        tool.Equipped:connection(equip)
        -- ^ This won't equip it...
        game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false)
        move:Destroy()
print("Entered")    
end


bin.Selected:connect(function(mouse) mouse.Button1Click:connect(Click) end)

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