How do I make it so you lose your tools in an area and you get them back when you leave that area?
Well, there is many ways to do that. You can save clones in a table, which will be probably the best option for you; you can also predefine tools that you will have after leaving the area and just clone it into player’s backpack; you can do this literally many ways.
Not what I meant by predefine tools. Basically, the tools you have when you spawn go away until you get out of spawn
script.Parent.Touched:Connect(function(hit)
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
if plr then
local bp = plr.BackPack
local folder = Instance.new("Folder",game.ReplicatedStorage)
folder.Name = plr.Name..'Tools'
for i,v in pairs(bp:GetChildren()) do
if v:IsA("Tool") then
v.Parent = folder
end
end
end
script.Parent.TouchedEnded:Connect(function(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player == plr then
for i,v in pairs(game.ReplicatedStorage:FindFirstChild(plr.Name..'Tools'):GetChildren()) do
if v:IsA("Tool") then
v.Parent = player.Backpack
end
end
game.ReplicatedStorage:FindFirstChild(plr.Name..'Tools'):Destroy()
end
end) --Add another 'end)' after this one. But for some reason I couldn't type it in here. Im new to being a member.
Basically you have a part that surrounds the safe zone. And when it’s touched and some enters the safe zone it puts there tools in a safe place.
This didn’t work, I added a part and added a script then added in the script and committed it and tried it out in studio.
Oh. The issue was I typed ‘BackPack’ instead of ‘Backpack’. Try that.
I would recommend using this module:
Get the player, and then when touching the safe part, use a client sided script to disable your inventory/backpack GUI.
It worked but how do I make it so they receive the tools back outside of the safezone?
script.Parent.Touched:Connect(function(hit)
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
if plr then
local bp = plr.Backpack
local folder = Instance.new("Folder",game.ReplicatedStorage)
folder.Name = plr.Name..'Tools'
for i,v in pairs(bp:GetChildren()) do
if v:IsA("Tool") then
v.Parent = folder
end
end
end
script.Parent.TouchedEnded:Connect(function(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player == plr then
for i,v in pairs(game.ReplicatedStorage:FindFirstChild(plr.Name..'Tools'):GetChildren()) do
if v:IsA("Tool") then
v.Parent = player.Backpack
end
end
game.ReplicatedStorage:FindFirstChild(plr.Name..'Tools'):Destroy()
end
end)
end)
Ok so I fixed the script from earlier. The TouchEnded function SHOULD do the trick, tbh. If this script doesn’t work I have another idea
It works but it doesn’t give the tools back outside of the safezone
How do I make it so it gives them back their tools outside of the safezone?
script.Parent.Touched:Connect(function(hit)
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
if plr then
local bp = plr.BackPack
local folder = Instance.new("Folder",game.ReplicatedStorage)
folder.Name = plr.Name..'Tools'
for i,v in pairs(bp:GetChildren()) do
if v:IsA("Tool") then
v.Parent = folder
end
end
end
end)
script.Parent.TouchedEnded:Connect(function(hit)
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
if plr then
local folder = game.ReplicatedStorage:FindFirstChild(plr.Name..'Tools')
if folder then
for i,v in pairs(folder:GetChildren()) do
if v:IsA("Tool") then
v.Parent = plr.Backpack
end
end
end
end
end)
Try this.
Still doesn’t I receive the backpack error although I fixed it and committed it.
Oh Lowercase p. I forgot
Make it ‘Backpack’ instead
Well the error still says it’s called ‘BackPack’ instead of Backpack. Did you commit the script?
Yes I did, I think it’s broke.