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