Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How would I detect flag captures?

Asked by 10 years ago

Take this as a question and not a request.

How would I detect when someone captures a flag on a team because I'm making a CTF gamemode. What events would I use to achieve this.

My leaderboard script

1local stats = {"value", "Omegite", "Captures"}
2 
3game.Players.PlayerAdded:connect(function(player)
4    local leaderstats = Instance.new("Model", player)
5    leaderstats.Name = "leaderstats"
6    for _, stat in pairs(stats) do
7        Instance.new("IntValue", leaderstats).Name = stat
8    end
9end)
0
What makes the flag do anything? BlueTaslem 18071 — 10y
0
when a person on a team caps it adds 1 to their team score rabidhalofan12345 55 — 10y
0
i dont really know what you mean rabidhalofan12345 55 — 10y

1 answer

Log in to vote
0
Answered by 10 years ago

Try this script:

01function findAllFlagStands(root)
02    local c = root:children()
03    for i=1,#c do
04        if (c[i].className == "Model" or c[i].className == "Part") then
05            findAllFlagStands(c[i])
06        end
07        if (c[i].className == "FlagStand") then
08            table.insert(stands, c[i])
09        end
10    end
11end
12 
13function hookUpListeners()
14    for i=1,#stands do
15        stands[i].FlagCaptured:connect(onCaptureScored)
View all 56 lines...
0
"stands" cant be defined rabidhalofan12345 55 — 10y
0
Hm...What's the name of your flag? It should work if a flag has a flag property named "FlagStand" regardless of the color. CowardlyArnold 20 — 10y
0
Ok I see the probelm. The stands are being detected because i'm doing map changes so when the game starts they are in a lobby. Is there a solution to this? rabidhalofan12345 55 — 10y
0
i have my leaderboard script edited into the post rabidhalofan12345 55 — 10y
Ad

Answer this question