I've tried altering a giver to instead ClearAllChildren from the player's backpack, and I've tried this recent code:
function getPlayer(humanoid) local players = game.Players:children() for i = 1, #players do if players[i].Character.Humanoid == humanoid then return players[i] end end return nil end script.parent.Touched:connect(function(hit)--Touched event humanoid=hit.Parent:FindFirstChild("Humanoid")--Finding the Humanoid if humanoid ~=nil then--If the humanoid exists local player = getPlayer(humanoid) if (player == nil) then return end player.Backpack:ClearAllChildren()--ClearsPlayerInventory end end)
But even through many different kinds of articles and such about things similar to this, I can't figure it out. Any help? Thanks.
I notice you're over complicating this, and i see two mistakes.
game.Players:GetPlayerFromCharacter(Character)
.script.parent
instead of script.Parent
(capital P).How to do this the short way:
script.Parent.Touched:connect(function(hit) if hit.Parent:FindFirstChild("Humanoid") then local player = game.Players:GetPlayerFromCharacter(hit.Parent) player.Backpack:ClearAllChildren() end end)
Any questions? Comment below ;D
Edit:
To clear the character from any tool we can do the following:
Loop through the character
Find all objects that have a className of "Tool"
Delete them
I'm adding this into the previous script.
script.Parent.Touched:connect(function(hit) if hit.Parent:FindFirstChild("Humanoid") then --clear backpack local player = game.Players:GetPlayerFromCharacter(hit.Parent) player.Backpack:ClearAllChildren() --Remove any equiped tools. for _,v in pairs(hit.Parent:GetChildren()) do if v:IsA("Tool") then v:Destroy() end end end end)
Here is a simple way to do it. You're overthinking this WAY too much, buddy. But it's okay, just keep watching tutorials and reading stuff on ROBLOX Lua until you feel comfortable and you feel good with it. But here is some help:
local clearinvenbrick = game.Workspace.ClearInvenBrick --[[ you can name the variable and brick anything you want, doesn't matter honestly.just rename and replace all the names and variables i'm putting if you want.--]] clearinvenbrick.Touched:connect(function(hit)--function when touching brick local humanoidhealth = hit.Parent.Humanoid.Health--[[variable for finding humanoid's health--]] local humanoid = hit.Parent:FindFirstChild("Humanoid")--variable for finding humanoid local player = game.Players:GetPlayerFromCharacter(hit.Parent) --[[variable for finding player--]] local backpack = player:FindFirstChild("Backpack") -- variable for finding backpack if humanoid and humanoidhealth > 0 then -- checking if it is a real player humanoid:UnequipTools() --unequips tools that are equipped backpack:ClearAllChildren()--takes tools away end end)