Specific Tool Boundary Script

Hi, I need to make a script that when you walk out of this boundary it removes a specific tool from your character or backpack and puts it back to where you got it. I know it’s possible but I haven’t been able to figure out how to do it. Let me know if you need anything to help.

1 Like

Hey there!
Check out this resource: Intro to Region3s (Detecting parts & generating Terrain) - Roblox Studio - YouTube

Once you’ve followed his steps (up to around the 8 minute mark), you’ll be able to keep a list of who is in the region (and by elimination, who isn’t), and give/remove tools appropriately.

4 Likes

Use raycast to detect when the player leaves the boundary and detect their backpack and remove the tool. then add whatever you want

1 Like

I’ve never heard of Raycast, can you describe how it would fit my situation?

1 Like

Ray cast is like a laser shooting from a point to another, its much better than using region3 or Touched events. I’d recommend you look it up.

Now, if you’re lazy and want to keep stuff simple, you can use .TouchEnded event on the part to detect when player leaves, with something like this:

local part = --put the location of your part here.
part.TouchEnded:Connect(function(hit)
      if hit.Parent:FindFirstChild("Humanoid") then --checks if the hit part has a humanoid, or in other words check if this is a player
            local char = hit.Parent --character variable
            local player = game.Players:GetPlayerFromCharacter(char) --player variable
            local tool = player.Backpack:FindFirstChild("TOOL NAME") --tool variable
            game.Debris:AddItem(tool) --debris is like the trash can of the game
      end
end)

if the script looks weird its bc i wrote it on my phone.

2 Likes

You can learn about raycast on the roblox documentation here : Raycasting | Documentation - Roblox Creator Hub

2 Likes

Thanks for linking the documentation man!

1 Like

Thank you, I will defiantly look into raycasting!!

2 Likes

I tried this code out just to see and it comes up with the error:

ServerScriptService.Script:16: attempt to index nil with ‘FindFirstChild’

Did I just not put it in the right place?

1 Like

Line 16? I don’t really have much information to help you, can you send the full script?

1 Like

Oop sorry, I was trying some stuff out before that but I made those into notes. Here is the script:

local part = game.Workspace.Barrier --put the location of your part here.
	part.TouchEnded:Connect(function(hit)
		if hit.Parent:FindFirstChild("Humanoid") then --checks if the hit part has a humanoid, or in other words check if this is a player
		local char = hit.Parent --character variable
		local player = game.Players:GetPlayerFromCharacter(char) --player variable
		local tool = player.Backpack:FindFirstChild("Dodgeball") --tool variable
		game.Debris:AddItem(tool) --debris is like the trash can of the game
	end
	end)
1 Like

Did the tool get deleted though?

No, it remained in my inventory after I removed myself from the block barrier thing

Well i guess you equipped the tool when testing, you should change that line to:

local tool = player.Backpack:FindFirstChild("Dodgeball") or char:FindFirstChild("Dodgeball")

That seems to work, is there a way that instead of it deleting, it goes back to where I grabbed it?

What do you mean by where you grabbed it?

So the dodgeball starts off on the ground in the arena, when I grab it or I guess pick it up then leave the area it deletes.

Well instead of deleting using the debris service i guess you can parent the tool to the workspace and change the Handle’s CFrame to where it was originaly.

If you don’t know what CFrame is it’s pretty much position and orientation

That will work, thank you so much!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.