Use ZonePlus module for hardpoint system

I posted a forum on how to make a hardpoint system before but so far i’ve gotten no answer. I got some ideas but none of them worked so far.

One guy told me to use GetPartsInBound which im trying right now and might work but i was wondering if i can use ZonePlus for the system instead since its pretty much the same(I think). I dont know if it can’t be used or am just doing something wrong here is my code so far.

local RS = game:WaitForChild("ReplicatedStorage")

--Modules
local zone = require(RS:WaitForChild("Modules"):WaitForChild("Zone"))
local ZonePlrs = require(game.ServerScriptService.Script.PlrsInZone)
local config = require(script.Config)

--Folders
local PointsFolder = workspace.HardPointFolder
local events = RS:WaitForChild("Events")

--Events
local pointChanged = events:WaitForChild("PointChanged")
local pointCaptured = events:WaitForChild("PointCaptured")

--Points
local points = require(game.ReplicatedStorage.Points)

--Points Vars
local activePoint = nil
local captured = false
local capturing = false
local captureProgress = 0
local curPoint = nil
local capturingPlayersCount = 0

local function activatePoint(point)
	if activePoint and captured  then
		activePoint.Trigger.Transparency = 1
		activePoint.Trigger.BrickColor = BrickColor.new("White")
		activePoint.Display.BillboardGui.Title.BackgroundColor3 = BrickColor.new("White").Color
		activePoint.Display.BillboardGui.Enabled = false
		capturing = false
	end
	
	activePoint = point
	activePoint:WaitForChild("Trigger").Transparency = 0
	activePoint.Display.BillboardGui.Enabled = true
	curPoint = point
	
	local newpoint = zone.new(point.trigger)
end

local function SelectPoint()
	local list = {}

	for _, v in ipairs(PointsFolder:GetChildren()) do
		if v and v ~= curPoint then
			table.insert(list,v)
		end
	end
	local index = math.random(1, #list)
	activatePoint(list[index])
end

SelectPoint()

I’ve also tried making a newpoint variable with a nil value and set it to a new point within the function but it didnt work

i’ve also tried putting the newpoint outside the functions and putting it at the end but still didnt work im so lost in this problem but i really want to solve it.

2 Likes

So far, from what I’ve seen, you’ve done the setup correctly, but you aren’t looking to see if a player has entered the zone or not.

According to the API, you can detect when a player has entered the zone, like so:

zone.playerEntered:Connect(function(player)
    print(("player '%s' entered the zone!"):format(player.Name))
end)

(The code shown is taken from the API).

2 Likes

nvm im stupid i cant believe i got stuck with this

so the reason was because i didnt do playerEntered

local RS = game:WaitForChild("ReplicatedStorage")

--Modules
local zone = require(RS:WaitForChild("Modules"):WaitForChild("Zone"))
local ZonePlrs = require(game.ServerScriptService.Script.PlrsInZone)
local config = require(script.Config)

--Folders
local PointsFolder = workspace.HardPointFolder
local events = RS:WaitForChild("Events")

--Events
local pointChanged = events:WaitForChild("PointChanged")
local pointCaptured = events:WaitForChild("PointCaptured")

--Points
local points = require(game.ReplicatedStorage.Points)

--Points Vars
local activePoint = nil
local captured = false
local capturing = false
local captureProgress = 0
local curPoint = nil
local capturingPlayersCount = 0

local function activatePoint(point)
	if activePoint and captured  then
		activePoint.Trigger.Transparency = 1
		activePoint.Trigger.BrickColor = BrickColor.new("White")
		activePoint.Display.BillboardGui.Title.BackgroundColor3 = BrickColor.new("White").Color
		activePoint.Display.BillboardGui.Enabled = false
		capturing = false
	end
	
	activePoint = point
	activePoint:WaitForChild("Trigger").Transparency = 0
	activePoint.Display.BillboardGui.Enabled = true
	curPoint = point
	
	local trigger = point.Trigger
	
	local newpoint = zone.new(point.Trigger)
	
	newpoint.playerEntered:Connect(function()
		print("player has entered")
	end)
end

local function SelectPoint()
	local list = {}

	for _, v in ipairs(PointsFolder:GetChildren()) do
		if v and v ~= curPoint then
			table.insert(list,v)
		end
	end
	local index = math.random(1, #list)
	activatePoint(list[index])
end

SelectPoint()

but before i did it like this and it never worked so i must have done something right this time

2 Likes

yeah it was my mistake i rushed and changed the code because i also tried to make the capturing part in a module script which didnt work either and changed it back but i forgot to add back the playerEntered but its all good now thanks for the reply

2 Likes

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