Backpack tool show

Hello everyone! How can I make it so that when the player is knocked out he can’t see his backpack and use his tools? I tried this code but it doesn’t work

game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack,false)

local Reviveui = game:GetService("ServerStorage"):WaitForChild("ReviveGUI")

local Bool = game.ReplicatedStorage:WaitForChild("Break")

local Animation = script.KnockOutIdle

game.Players.PlayerAdded:Connect(function(player)

player.CharacterAdded:Connect(function(char)

local humanoid = char:WaitForChild("Humanoid")

repeat wait() until humanoid

local KnockAnim = humanoid:LoadAnimation(Animation)

humanoid:GetPropertyChangedSignal("Health"):Connect(function()

if humanoid.Health <= 20 then -- The Knockout Value Is Under 20 Health

Bool.Value = false

-- Knockout

KnockAnim:Play() -- Plays Animation

humanoid.WalkSpeed = 0 -- Can't Move

humanoid.JumpHeight = 0 -- Can't Jump

char:WaitForChild("Health").Disabled = true -- Disables Healing So We Could Revive

-- Get The GUI For Informing And The Click Detector For Reviving Also A ForceField So No One Can Kill When Knock

local ClonedUi = Reviveui:Clone()

ClonedUi.Adornee = char.Head

ClonedUi.Parent = char.Head

local FF = Instance.new("ForceField",char)

FF.Visible = false

local CD = Instance.new("ClickDetector",char.UpperTorso)

-- Reviving System!

CD.MouseClick:Connect(function()

humanoid.Health = humanoid.Health + 5 -- Replace 3 With Ur Healing Number

end)

-- Bleeding | The Health Goes Down OverTime If Not Revived

while wait(5) do

if Bool.Value == false then

humanoid.Health = humanoid.Health - 0 -- Replace 3 With Ur Bleeding Number

elseif Bool.Value == true then

break

end

end

end

end)

-- When Reached 50 Health Reviving Stops And Player Heals On His Own

humanoid:GetPropertyChangedSignal("Health"):Connect(function()

if humanoid.Health >= 50 then

Bool.Value = true

humanoid.WalkSpeed = 16

humanoid.JumpHeight = 7.2

char:WaitForChild("Health").Disabled = false

KnockAnim:Stop()

for _,v in pairs(char.Head:GetChildren()) do

if v:IsA("BillboardGui") then

v:Destroy()

end

end

for _,v in pairs(char.UpperTorso:GetChildren()) do

if v:IsA("ClickDetector") then

v:Destroy()

end

end

if char:FindFirstChild("ForceField") then

char.ForceField:Destroy()

end

end

end)

end)

end)
1 Like

Is this inside a server script or local script?

it is a script and it is in ServerScriptService

Oh I see,
game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack,false) does not work on the server side.

You could try and use a RemoteEvent and fire the client whenever you want the players tools to be disabled. RemoteEvent:FireClient(player)

Example: (Setup)
image

Script Inside ServerScriptService: (Named Test)

local Remote = game:GetService("ReplicatedStorage"):WaitForChild("Remote") --Referencing the remote in ReplicatedStorage

game:GetService("Players").PlayerAdded:Connect(function(player)
	wait(2) -- Waits 2 seconds, giving time for the player to load in
	
	Remote:FireClient(player, "DisableTools") --Fires the remote telling it to disable tools
	
	wait(2) -- Testing Purposes
	
	Remote:FireClient(player, "EnableTools") --Fires the remote telling it to enable tools
end)

Script Inside StarterGui: (Named Reciever)

local Remote = game:GetService("ReplicatedStorage"):WaitForChild("Remote") --Referencing the remote inside Replicated Storage

Remote.OnClientEvent:Connect(function(info)
	if info == "DisableTools" then --If the info passed through the remote from the server side is == "DisableTools" then
		game:GetService("StarterGui"):SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false) --Disables Tools
	end
	if info == "EnableTools" then --If the info passed through the remote from the server side is == "Enable Tools" then
		game:GetService("StarterGui"):SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, true) --Enables Tools
	end
end)

thank you very much, but how do I add the script to my serverscriptservice script?

If I were you I’d just unequip any of the humanoid’s equipped tools and then destroy all of the tool instances in their backpack, no need for server to client communication.

humanoid:UnequipTools()
for _, tool in ipairs(backpack:GetChildren()) do
	if tool:IsA("Tool") then
		tool:Destroy()
	end
end
1 Like

Ok, but how do I get those tools back?

local replicated = game:GetService("ReplicatedStorage")
local folder = Instance.new("Folder")
folder.Parent = replicated

humanoid:UnequipTools()
for _, tool in ipairs(backpack:GetChildren()) do
	if tool:IsA("Tool") then
		tool.Parent = folder
	end
end

for _, tool in ipairs(folder:GetChildren()) do
	tool.Parent = backpack
end

You’d need to collect the tools inside a folder which can be referenced later.

it doesn’t work, there is an error in this part folder.Name = player.Name.."Folder"

That code shouldn’t be copied & pasted by the way.

It was just pseudo-code to help direct you.

ah ok, with reason, in the same way thanks for always helping!

You don’t have to do repeat until wait

:WaitForChild() itself will wait for the child and you don’t have to repeat it

Actually the script is not mine, but from a youtube tutorial that teaches how to make a revive system, but he forgot to hide the tools