Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why doesn't this disable the persons backpack tools?

So I have a working handcuff, but when you cuff another person and that person cuffs you, you go flying, I have a simple solution, When that player is handcuffed, they can't use their tools. Here is the script inside of the handcuffs, they still work with this script, The just don't disable the other person's backpack. Sorry long code, The code that I put into it is on line 48, and line 68.

local RemoteEvent = script.Parent:WaitForChild("RemoteEvent")
local TargetTorso = nil
local Using       = false


function CheckForTargetTorso(part)
	if part.Parent:IsA'Model' and part.Parent:FindFirstChildOfClass'Humanoid' then
		local char = part.Parent
		local torso
		if char:FindFirstChild'Torso' then
			torso = char.Torso
		elseif char:FindFirstChild'UpperTorso' then
			torso = char.UpperTorso
		end
		return char, torso
	end
end

	
	
function CheckForTorso(player)
	local Char = player.Character
	if Char:FindFirstChild'Torso' then
		return Char.Torso
	else 
		return Char.UpperTorso
	end
end


RemoteEvent.OnServerEvent:Connect(function(player, state, part)
	
	if state == 'Cuff' then
		local target      = nil
		local playerTorso = nil
		
		target, TargetTorso = CheckForTargetTorso(part)
		playerTorso = CheckForTorso(player)
		
		if target then
			Using = true
			RemoteEvent:FireClient(player, 'Use')
			spawn(function()
				if Using then
					TargetTorso.Anchored = true	
					TargetTorso.CanCollide = true
					
for i, Toolsxd in pairs(player.Backpack:GetChildren()) do
    if Toolsxd:IsA("Tool") then
        Toolsxd.Enabled = false
    end
end
	
				end				
				while Using and wait() do			
					TargetTorso.CFrame = playerTorso.CFrame * CFrame.new( 0, 0, -5 )
				end				
				
			end)			
			
		end
	
	elseif state == 'UnCuff'then	
		Using = false		
		TargetTorso.Anchored = false
		TargetTorso.CanCollide = false
		for i, Toolsxd in pairs(player.Backpack:GetChildren()) do
    if Toolsxd:IsA("Tool") then
        Toolsxd.Enabled = true
    end
end
		wait()
	end
	
end)

1 answer

Instead of disabling all the tools in the player's backpack, you can simply just disable backpack. This can be done by using a RemoteEvent to go from the Server to the Client, which I will demonstrate.

Since you are already using a RemoteEvent, you can pass an argument in that RemoteEvent that is specific to disabling the Backpack of the player.

For example:

On Server (Script):

local BackpackEnabled = game.ReplicatedStorage.BackpackEnabled -- A RemoteEvent in ReplicatedStorage

RemoteEvent.OnServerEvent:connect(function(player, state, part)
	-- This is where you have your main code on the server script
	if state == "Cuff" then
		-- This is what happens when you are cuffed
		BackpackEnabled:FireClient(player, true)
	elseif state == "UnCuff" then
		-- This is what happens when you are uncuffed
		BackpackEnabled:FireClient(player, false)
	end
end)

On Client (LocalScript):

local BackpackEnabled = game.ReplicatedStorage.BackpackEnabled -- A RemoteEvent in ReplicatedStorage
local StarterGui = game.StarterGui

BackpackEnabled.OnClientEvent:connect(function(Enabled)
	StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, Enabled)
end)

This basically makes it so that the StarterGui Enables or Disables the Backpack gui based on whether the player is cuffed or not.

I hope this helps and if not, let me know on how I can further clarify this method! :D

3 comments

0

Thanks for the answer! Let me try it out.

0

Hm didn't work, I put it where i needed to put it, And I made a seperate Local Script for the other thing.

0

And yes, I added a RemoteEvent in Replicated Storage.

This discussion is preserved as it was. New answers, comments, and votes are closed.