Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I make a capture script for a King Of The Hill (teams) game?

I am making a raiding simulation for my small military with 2 fellow developers. It is going to be a team king of the hill and I'm not entirely sure how to make it capture. I've already got the transparent and noncancollided parts, and it has all been build, I'm just not quite sure how to program it. Here's a picture of the Workspace: https://imgur.com/a/jOB2a1a

Any suggestions on how to make it? Thanks!

1 answer

✓ Accepted answer

I suggest you use Region3 to check who currently on the hill.

local charTable = {}
local inHillRegion = {}
local zone = workspace:FindFirstChild("Capture").Capture
local pos1 = zone.Position - (zone.Size/2)
local pos2 = zone.Position + (zone.Size/2)
local region = Region3.new(pos1,pos2)

while wait() do
	inHillRegion = nil
	local partsInRegion = workspace:FindPartsInRegion3(region,charTable,1000)
	for i,v in pairs(partsInRegion)do
		local thisChar = v.Parent
		local player = game.Players:GetPlayerFromCharacter(thisChar)
		if inHillRegion[player.UserId] = nil then
			inHillRegion[player.UserId] = thisChar
		end
	end
	--Do anything you want to the players in here
end

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(char)
		charTable[player.UserId] = char
	end)
	player.CharacterRemoving:Connect(function()
		charTable[player.UserId] = nil
	end)
end)

I havent tested this but it might work

Edit* if you still need it, heres the working script. Make sure you put it in the capture zone part

local inHillRegion = {}
local zone = script.Parent
local pos1 = zone.Position - (zone.Size/2)
local pos2 = zone.Position + (zone.Size/2)
local region = Region3.new(pos1,pos2)

while wait(.5) do
    inHillRegion = {}
    local partsInRegion = workspace:FindPartsInRegion3(region,nil,500)

	for i,v in pairs(partsInRegion)do
		if v.Parent:FindFirstChild("HumanoidRootPart") and v.Parent:FindFirstChild("Humanoid") and v.Parent:FindFirstChild("Head") then
			local player = game.Players:GetPlayerFromCharacter(v.Parent)
			if inHillRegion[player.UserId] == nil then
				inHillRegion[player.UserId] = v.Parent
			end
		end
	end
	for i,v in pairs(inHillRegion)do
	    --Do anything you want to the players in here
	end
end

2 comments

0

Checking it now.

0

Forgot to add that you should make the while loop wait a bit longer before repeating

This discussion is preserved as it was. New answers, comments, and votes are closed.