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

How do you call a function?

Asked by
thePyxi 179
8 years ago

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)
0
tool.Equipped:connect(equip) but btw there's more stuff wrong with your script I believe DarwinYork 85 — 8y
0
I'll edit it so I can be able to put the entire code thePyxi 179 — 8y
0
@DarwinYork thePyxi 179 — 8y

1 answer

Log in to vote
1
Answered by 8 years ago

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)
Ad

Answer this question