I want to prevent the player from unequipping a tool while they are using one of it’s abilities. How can I achieve this?
For this you would need to disable the backpack gui on the client using:
game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack,false)
and then re-enabling it when it’s done with the ability. When the gui is disabled the player still has the tool but they cannot unequip it as the gui does not exist. Unfortunately there’s no easy way (outside of disabling the backpack entirely) to stop a player from unequipping a tool unless you code your own tool system outside of roblox’s built-in one.
Alternatively, you could just make abilities only occur depending on if you’re holding the tool or not, and then if the player unequips the tool while the ability is happening it would stop the ability.
wouldnt i need to do game.Players.LocalPlayer.PlayerGui rather than game.StarterGui?
also, would i have to reload the character for this to work, or would it immediately work?
SetCoreGuiEnabled is a function of StarterGui;
To get the correct result, turn this to a LocalScript under StarterGui:
local StarterGui = game:GetService("StarterGui")
StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false)
This is a code snippet to work in addition to any existing code you have!
(Note: This must be a LocalScript for it to only change for the given client, not the server!)
Ok, but again, if I used this, would it immediately work, or would it only take affect after reloading the character?
Edit: I also have this in a remote event, can I reference the player’s StarterGui through the parameter in the remote event?
It would immediately work. Also, you could if you have a valid Player parameter.
players still being able to unequip tools even if the backpack gui is disabled, by pressing backspace button.
I think something like this using Humanoid.EquipTool could work.
local Players = game:GetService("Players")
local canUnequip = false
tool.Unequipped:Connect(function()
local player = Players:GetPlayerFromCharacter(tool.Parent)
local humanoid = player.Character:FindFirstChildOfClass("Humanoid")
if not canUnequip then
humanoid:EquipTool(tool)
end
end)
This will not work, the purpose of this property is to prevent removing the tool from its inventory, not preventing it from unequipping it.
… they already had the unequipping part done, i was helping them with the part where they can just press backspace
I was replying to this fellow developer
Oh sorry, I think I read the post a bit too quickly and sideways.
Glad to know they fixed it.
I would create a bug thread to report this. But I can’t create them for some reason.
a bug about…?
also, only people who have the Regular rank can create bug reports