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

How to auto equip a tool when a GUI button is pressed?

So I'm trying to make a tool equip when a GUI button is pressed while the default backpack GUI is disabled. I got the backpack GUI disabled now all I need is the tool equipper

I've tried this

local UserInput = game:GetService("UserInputService")
local Player = game:GetService("Players").LocalPlayer
local Character = Player.Character or Player.CharacterAdded:wait()
local Tool = game:GetService("ReplicatedStorage").PL42

UserInput.InputBegan:connect(function(Input)
	script.Parent.Buttons.Frame.TextButton.MouseButton1Click:Connect(function()
		wait(1)
		Tool.Parent = Character
	end)

end)

and it literally did nothing, can someone help?

4 comments

0

if im not wrong placing it in the character should work

0

also u shouldnt need to disable backpack

0

wait nvm

0

do it from a server script?

2 answers

ISSUES

You don't need the UIS to activate a GuiButton

Tools go into the player's Backpack to be transferred to the player Character, not directly to the character

Use Activated since it works for all devices while MouseButton1Click does not.

Revised Local Script

local Player = game:GetService("Players").LocalPlayer
local Tool = game:GetService("ReplicatedStorage"):WaitForChild("PL42")

script.Parent.Buttons.Frame.TextButton.Activated:Connect(function()
	wait(1)
	Tool.Parent = Player.Backpack
end)

3 comments

0

so it'll not auto equip?

0

what about humanoid:Equiptool(Tool)

0

:WaitForChild() overkill

This should work

local UserInput = game:GetService("UserInputService")
local Player = game:GetService("Players").LocalPlayer
local Character = Player.Character or Player.CharacterAdded:wait()
local Tool = game:GetService("ReplicatedStorage").PL42

UserInput.InputBegan:connect(function(Input)
    script.Parent.Buttons.Frame.TextButton.MouseButton1Click:Connect(function()
        Tool.Parent = Player.Backpack
        wait()
        Tool.Parent = Character

    end)

end)

this worked for me but idk if they fixed it or not

1 comment

0

well it technically in't a fix, bt more like a change

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