You could’ve at least attempted to make the script, by searching for general Region3 questions.
Anyways, Region3.new is used to create a new Region, and it has two parameters / arguments, which are min and max. The way Region3’s are made is that they form a box from two corners: min (being the top-left), and max (being the bottom-right). So we can write a function to create a function from a given position and size:
function createRegion3(pos, size)
return Region3.new(pos - (size / 2), pos + (size / 2))
end
So, we have a region created, we now want to constantly register new players in the Region3 and give them the tool, and deregister leaving players and remove the tool. We can do this with a while loop:
-- plate is just the part you want the players to stand on to receive the tool. The Region3's size is increased by 10 studs to allow players to registered
local region = createRegion(plate.Position, plate.Size + Vector3.new(0, 10, 0))
local list = {} -- holds players who are currently in the region
while true do
local newlist = {} -- used for reiterating through the players in the region3 and updating the list
-- Arguments for FindPartsInRegion3: region, ignoreDescendantsModel, maxParts
-- we want to ignore the plate itself in the table, so plate is the 2nd argument, and we want to get as many players in the region3, so maxParts is set to math.huge (the biggest number that roblox can get)
local parts = workspace:FindPartsInRegion3(region, plate, math.huge)
for _, v in pairs(parts) do
local player = game.Players:GetPlayerFromCharacter(v.Parent)
if player then -- verifying if it is a player who is in the region
if not table.find(list, player) then -- checking if the player is not in the table
list[#list + 1] = player -- adding player to the main list
newlist[#newlist + 1] = player -- also adding player to the new list
tool:Clone().Parent = player.Backpack -- giving the player the tool (tool is the tool you want the player to have)
end
end
end
for _,v in pairs(game.Players:GetPlayers()) do
if not table.find(newlist, v) then -- checking if the current player is not in the newlist
local index = table.find(list, player) -- finding if the player is in the table, if found, retrieve the index of the entry they're in
if index then -- we found the index
table.remove(list, index) -- removing the player from the list
if player.Character and player.Character:FindFirstChild(tool.Name) then -- if the player's character exists, we'll try to find the tool in the player's character. If found, it means that the player has equipped the tool
player.Character[tool.Name]:Destroy()
elseif player.Backpack:FindFirstChild(tool.Name) then
player.Backpack[tool.Name]:Destroy()
end
end
end
end
wait() -- yielding the script of course, we don't to cause the script to time-out
end
Resources: