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
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)
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)
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)
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
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.