Hi, I’m trying to make a command that when a textbutton is pressed it fires an event that send to a server script (both scripts are located inside the button) and disables the typed player’s tool. It works when the player has their tool unequipped and it’s located in their backpack, but it doesn’t work when the player has the tool equipped, located in their character model.
Here’s my Local Script:
local CollectionService = game:GetService("CollectionService")
local players = game:GetService("Players")
local player = players.LocalPlayer
local char = player.Character
local Remote = script.Parent.Parent:WaitForChild("NeutralizeRemote")
local Remote2 = script.Parent.Parent:WaitForChild("NeutralizeRemoteEquipped")
local playerusernamebox = script.Parent.Parent:WaitForChild("PlayerUsername")
script.Parent.MouseButton1Up:Connect(function()
local playerToNeutralize = playerusernamebox.Text
local TargetPlayer = players:FindFirstChild(playerToNeutralize)
print("Found target player: " .. TargetPlayer.Name .. ".")
local TargetPlayerCharacter = game.Workspace:FindFirstChild(TargetPlayer.Name)
print("Found " .. TargetPlayer.Name .. "'s character.")
local TargetPlayerHumanoid = TargetPlayerCharacter:FindFirstChildOfClass("Humanoid")
print("Found " .. TargetPlayer.Name .. "'s humanoid.")
local TargetPlayerBackpack = TargetPlayer:WaitForChild("Backpack")
print("Found " .. TargetPlayer.Name .. "'s backpack.")
if TargetPlayer then
local ToolToDisable = TargetPlayerBackpack:FindFirstChildWhichIsA("Tool")
local ToolToDisableCharacter = TargetPlayerCharacter:FindFirstChildWhichIsA("Tool")
if ToolToDisable and CollectionService:HasTag(ToolToDisable, "Weapon") then
Remote:FireServer(TargetPlayer, TargetPlayerCharacter, TargetPlayerHumanoid, ToolToDisable)
print(player.Name .. " fired the neutralize remote for: " .. TargetPlayer.Name .. ". (TOOL IS IN BACKPACK)")
elseif ToolToDisableCharacter and CollectionService:HasTag(ToolToDisable, "Weapon") then
Remote2:FireServer(TargetPlayer, TargetPlayerCharacter, TargetPlayerHumanoid, ToolToDisableCharacter)
print(player.Name .. " fired the neutralize remote for: " .. TargetPlayer.Name .. ". (TOOL IS IN CHARACTER)")
end
end
end)
Here’s my Server Script:
local Remote = script.Parent.Parent:WaitForChild("NeutralizeRemote")
local Remote2 = script.Parent.Parent:WaitForChild("NeutralizeRemoteEquipped")
Remote.OnServerEvent:Connect(function(plr, TargetPlayer, TargetPlayerCharacter, TargetPlayerHumanoid, ToolToDisable)
if plr then
if TargetPlayer and TargetPlayerCharacter and ToolToDisable then
ToolToDisable.Enabled = false
print("Disabled " .. TargetPlayer.Name .. "'s Tool: " .. ToolToDisable.Name .. ".")
end
end
end)
Remote2.OnServerEvent:Connect(function(plr, TargetPlayer, TargetPlayerCharacter, TargetPlayerHumanoid, ToolToDisableCharacter)
if plr then
if TargetPlayer and TargetPlayerCharacter and ToolToDisableCharacter then
TargetPlayerHumanoid:UnequipTools()
print("Unequipped " .. TargetPlayer.Name .. "'s Tool: " .. ToolToDisableCharacter.Name .. ".")
wait(0.1)
ToolToDisableCharacter.Enabled = false
print("Disabled " .. TargetPlayer.Name .. "'s Tool: " .. ToolToDisableCharacter.Name .. ".")
end
end
end)
P.S. I get no errors. and both remotes are in the button’s parent ( a Frame).
Please help. Thank you.