I’m making a script where the player can hold the tool inside a CUSTOM inventory and custom hotbar.
When the tool is equipped, I am just cloning it into the character. This is putting it correctly in the characters hand, however I don’t believe this will work. I’ve tried a few scripts to get it to simply print something on click, and nothing is working.
Is this way of doing it (cloning the tool from serverstorage and putting it into the players character) a bad way of doing it?
(btw doing tests with a default roblox sword without the scripts. So if that breaks anything please let me know how, it’s just the “tool” with a regular handle. It works quite nicely for a test before I make custom models for custom tools.)
The issue isn’t really due to the cloning, it’s because you’re using a custom inventory instead of the default backpack. The Activated event will only work if the Tool has been equipped first, and when using a custom inventory you’ll need to inform the Tool that it has been equipped in order for Activated to start working
And how exactly would I do that? this is the relevant part of the script.
for i, current in ipairs(toolFolder:GetChildren()) do
if current.Name == object.Name then
toolvalue.Value = true
newtool = current:Clone()
newtool.Parent = player.Character
end
Yes newtool is a variable outside of the loop, it makes it much easier for me to delete it once it needs to be deleted.
Since my tool is in ReplicatedStorage, I probably couldn’t do the first one like you said.
How would the second one work?
(Alternatively, could I just set the parent to the character before I use the equiptool function, since it would technically be inside workspace at that point in time.)
Thank you so much for your help, I’m quite new so I’m suprised I’ve been able to get this far with no tutorials, this surely will be a help in the long run.
For this to work they can try copying the behavior of the default tool/inventory system. Basically first parent said tool under the player character(so it’s inside the workspace), then call the EquipTool function for said tool.
I’m reading but not comprehending that completely.
Are you saying that the tool and the character need to have the same parent (workspace), when EquipTool is called? nvm after rereading it I think I understand now,
I’ve got no clue what the “behavior” of the default tool/inventory is. I’m COMPLETELY new to scripting, this is probably still only my second week of learning. I’ve never worked with tools before now.
Wait, another edit. Are you saying that what I said was correct, that if I make the tool a child of the player’s character, and THEN I equip the tool, it will mimic the default behavior of the inventory? I’ve been trying this for the past 20 minutes and now I’m starting to doubt if my script to detect if the tool is being activates is the problem lol
This is the script I’m using to detect if it’s working when I click, it’s not printing anything.
local player = game:GetService("Players").LocalPlayer
local mouse = player:GetMouse()
script.Parent.Activated:Connect(function(player)
mouse.Button1Down:Connect(function()
print "Activated"
end)
end)
This is what I’m using to equip the tool to the player, is anything from these incorrect?
for i, current in ipairs(toolFolder:GetChildren()) do
if current.Name == object.Name then
toolvalue.Value = true
newtool = current:Clone()
newtool.Parent = player.Character
task.wait()
player.Character.Humanoid:EquipTool(newtool)
end
end
I’m starting to suspect the issue might be happening because of something else since I’m unable to replicate this behavior when I test it myself, how are your Tool’s properties configured?
Is there anything else that could be causing this issue? Like character being locked to first person or literally anything like that you can think of?
Wait I believe I MAY have discovered the issue, it’s because my grab script. I tested it again by just putting the tool into workspace and walking over it with the grab script disabled. I think it may be because whenever I click it is trying to instead grab the tool? I’m not entirely sure but I’ll look into it
If your grab script uses ClickDetectors you can disable them while the Tool is equipped by setting the MaxActivationDistance to 0 or nil, then re-enable them again when the Tool is dropped
It unfortunately enough for me, is not using click detectors. There is no easy way out of this for me, I will probably have to rewrite huge chunks of code >:(