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

Equip and Unequip script not working?

Asked by 5 years ago
Edited 5 years ago

Hello, I'm developing a game, I want the script to be like,

-- If a person steps on it, it automatically unequips tool A and automatically equips tool B.

Can't seem to make it work.

local examplePart = game.Workspace.examplePart
local exampleTool = player.Backpack.ThisIsExample1
local exampleToolA =  player.ReplicatedStorage.ThisIsExample2


examplePart.Touched:Connect(onTouch)
exampleToolA.Parent.Equipped:connect(function()
print(omg its equipped lol)
exampleTool.Parent.Unequipped:connect(function()
print(omg its unequipped lol)
end)

I'm a beginner scripter but at least I tried. Any help would be appreciated, thanks! buz

0
What is the error its giving to you? and you can't print string without using quotations marks (" "), try using this print code: print("omg its equipped lol") vBaRaAx02 1 — 5y
0
And use :Connect() because :connect() is deprecated SirDerpyHerp 262 — 5y
0
And i think there are some "end" missing, because there are three functions and only one "end" mewant_taco 17 — 5y
0
Also at line 6 you are conenecting to a function called ("onTouch") when there's no function with that name mewant_taco 17 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

Hey i think i have fixed your problem.

First we will need a variable for the player: (make sure this is a Local Script)

local player = game.Players.LocalPlayer

Now we can do the full code!

First lets see the code you alredy have:

local examplePart = game.Workspace.examplePart
local exampleTool = player.Backpack.ThisIsExample1
local exampleToolA =  player.ReplicatedStorage.ThisIsExample2


examplePart.Touched:Connect(onTouch)
exampleToolA.Parent.Equipped:connect(function()
print(omg its equipped lol)
exampleTool.Parent.Unequipped:connect(function()
print(omg its unequipped lol)
end)

Ok now its the part where the magic happends. There's a way that you can force the tool equipment, its using Humanoid:EquipTool

So your script should look like this:

local player = game.Player.LocalPlayer

examplePart.Touched:Connect(onTouch)
Humanoid:EquipTool(exampleTool)
end
exampleToolA.Parent.Equipped:connect(function()
print(omg its equipped lol)
end
exampleTool.Parent.Unequipped:connect(function()
print(omg its unequipped lol)
end)

Unfortunatly idk if there's a way to unequip a tool using a script :/ For more information about this subject, check this article

I hope this works for you, if it doesn't send me a message!

(also if i spelled something wrong correct me, im portguese sry :/)

(and also im noob at scripting so it very probable that this doesn't work, but good luck)

0
Hey i found out that you can use this thing called "unequipTool(*tool name here*)" mewant_taco 17 — 5y
Ad

Answer this question