How Do You Tell If A Part Is In A Specific Area?

I’m creating a game that uses npcs to buy boats and have gotten everything I have wanted to work, except a boat detection system.

Basically, I wanted to have it so when a player buys a boat, if there is already a boat there that isnt the players it wont work.

If it also helps, I’ve added a String value equivalent to the player who owns each boat.

If anyone can help me I would be greatful

Proximity Prompt


script.Parent.Triggered:Connect(function(hit)
	if hit.Character:FindFirstChild("Humanoid") then
		game:GetService("ReplicatedStorage").Chats.SmallBoat:FireClient(hit)
	end
end)

LocalScript/ChatHandler


local debounce = false
local cooldown = 5

local Messages = {"So You Want To Buy My Viking Boat","It'll Cost You", "How does 500 Gold Sound?"}
local Reply1 = {"No?", "I Knew I Overpriced Didn't I"}
local Reply2 = {"I Knew You Were Smart", "A Deal Is A Deal", "Good Luck On Your Journey Traveller"}
local Reply3 = {"You Dont Have Enough Gold!", "You're Not Trying To Scam Me Now Are You?"}
game:GetService("ReplicatedStorage").Chats.VikingBoat.OnClientEvent:Connect(function(hit)
		if debounce == false then
			debounce = true

			local GUI = script.Parent.ScreenGui2:Clone()
			local Player = hit

			local Rig = game.Workspace.Ketil:Clone()

			GUI.Parent = script.Parent
		GUI.Frame.NpcName.Text = "Ketil"
		GUI.Enabled = true
		
		script.Parent.Parent.Character.Humanoid.WalkSpeed = 0
			Rig.Parent = GUI.Frame.ViewportFrame
			for i, v in pairs(Messages) do
				for i = 1, string.len(v) do wait(.025)
					script.Parent.NPC_70:Play()
					GUI.Frame.Dialogue.Text = string.sub(v, 1, i)
				end
				wait(1)
			end
			GUI.Frame.Yes.Visible = true
			GUI.Frame.No.Visible = true

			GUI.Frame.Yes.MouseButton1Down:Connect(function(plr)
				GUI.Frame.Yes.Visible = false
				GUI.Frame.No.Visible = false
				print(script.Parent.Parent.leaderstats.Gold.Value)
			if script.Parent.Parent.leaderstats.Gold.Value < 500 then
					for i, v in pairs(Reply3) do
						for i = 1, string.len(v) do wait(.025)
							script.Parent.NPC_70:Play()
							GUI.Frame.Dialogue.Text = string.sub(v, 1, i)
						end
						wait(1)
					end
				script.Parent.Parent.Character.Humanoid.WalkSpeed = 16
					debounce = false
					GUI:Destroy()
			else
				
				game:GetService("ReplicatedStorage").Chats.VikingBuy:FireServer(plr)
					for i, v in pairs(Reply2) do
						for i = 1, string.len(v) do wait(.025)
							script.Parent.NPC_70:Play()
							GUI.Frame.Dialogue.Text = string.sub(v, 1, i)
						end
						wait(1)
					end
				script.Parent.Parent.Character.Humanoid.WalkSpeed = 16
					debounce = false
					GUI:Destroy()
				end
			end)

			GUI.Frame.No.MouseButton1Down:Connect(function(plr)
				GUI.Frame.Yes.Visible = false
				GUI.Frame.No.Visible = false
				for i, v in pairs(Reply1) do
					for i = 1, string.len(v) do wait(.025)
						script.Parent.NPC_70:Play()
						GUI.Frame.Dialogue.Text = string.sub(v, 1, i)
					end
					wait(1)
				end
			script.Parent.Parent.Character.Humanoid.WalkSpeed = 16
				debounce = false
				GUI:Destroy()
			end)

end
end)

Boat Giver

game:GetService("ReplicatedStorage").Chats.VikingBuy.OnServerEvent:Connect(function(plr)
plr.leaderstats.Gold.Value = plr.leaderstats.Gold.Value - 500
for i , v in pairs(game.Workspace:GetDescendants()) do
	if v.Name == "Boat1"or v.Name == "Boat2" then
		if v.Owner.Value == plr.Name then
			v:Destroy()
		end
	end
end
local boat = game:GetService("ReplicatedStorage").Boats.Boat2:Clone()
boat.Position = Vector3.new(-1078.895, 71.659, -354.827)
boat.Parent = workspace
	boat.Owner.Value = plr.Name
	end)


1 Like

By using WorldRoot | Documentation - Roblox Creator Hub or Region3 | Documentation - Roblox Creator Hub

2 Likes

Thank You, But Is There Any Specific Method I Should Use?

2 Likes

What do you mean by that?

1 Like

In The Link You Sent, There Is Multiple Methods It Shows About How To Get Parts In An Object

1 Like

Oh, use :GetPartsInPart(Part,Params) where part means like a boundry part that detects all parts inside it and Params meaning OverlapParams.

2 Likes

I would recommend :GetPartBoundsInBox since it does not require a bounding box part.

1 Like