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

How can I make a capture the hill script?

I originally made a script where if a player from team A captures the hill, the hill turns to the team A colour, and if a player from team B captures the hill the hill turns to team B colour.

But I want to make it so that if there are 2 players from team A, the capture time halves and the points double, and if there are 3 players from team A, the points triple etc.

Likewise if there are 2 or more players from opposing teams standing on the hill, nothing happens.

I'm unsure how to script this.

The main thing I don't know how to do is how to detect whether there are more than 1 players on the hill, and how to detect there individual teams rather than just using a generic "user.TeamColor" etc.

Or is there a completely different and better way to go about all this?

Thanks.

Here's what I have:

part = game.Workspace.zone
debounce = false




function onTouch(hit)
	local user = game.Players:GetPlayerFromCharacter(hit.Parent)
	if not debounce then 
		debounce = true
	
if user.TeamColor == game.Teams.Mayhem.TeamColor
	then 
		wait(1)
		part.BrickColor = user.TeamColor 
	end
	debounce = false
	end
	
	
	
function onTouch2(hit)
	local user = game.Players:GetPlayerFromCharacter(hit.Parent)
	if not debounce then 
		debounce = true
		
if user.TeamColor == game.Teams.Peace.TeamColor
	then 
		wait(1)
		part.BrickColor = user.TeamColor 
		print(onTouch)
	end
	debounce = false
end
end
	


script.Parent.Touched:connect(onTouch)
script.Parent.Touched:connect(onTouch2)

if onTouch and onTouch2 then do
	part.BrickColor = part.BrickColor.new("Yellow")
		
	end
end	
end

		

15 comments

0

do you have an idea as to how it would work

0

pardon me?

0

Like a script idea.

0

I'll edit what I've put in before

0

You are using a lot of global variables, I first recommend to switch to local.

0

"My idea" of how to go about it is if some1 from Team A captures hill, a separate hill variable will say "Team A". Then if some1 from Team B captures hill, it will say Team B. If 2 separate people, hill will read Team A and Team B, and then it will do something else, but this doesn't work

0

why is that bad that I'm using a lot of global variables?

0

Global variables are bad practice, because they make code messy. No mean to be rude but your code is poorly indented, and the global variables are contributing to the messy code. They also pollute the global namespace, and can increase risks for name collisions.

0

Also, while many people don't seem to mind, local variables are only slightly faster to access than global variables.

0

In my game, I used distance and detect if a player is within a radius around the part (10 studs). I store the player object inside a table and with that you can get the number of players using #table.

0

You'll have to detect when the player leaves the distance to remove them from the table

0

I used GetDistanceFromCharacter in a localscript to detect if the local player is in the radius and if they are it will fire a remote to the server so it can store the player object inside the table. And if the player is greater than the radius it fires a different remote to let the server remove the player object from the table

0

thank you incapaz, no offence taken lol. and thank u unsatisfie_d

0

A lot of typing above ^

0

Np, you need to add a PlayerRemoving event to because the script can break when someone is capturing and leaves

1 answer

✓ Accepted answer

Well, first of all, values are crucial to any complex game having to do with math like this. Try having a stringValue to get how many people are on the hill for each individual team. After you have done this, do some "if then" statements about how fast the team will capture the point. For example:

function onTouch(hit)
    local user = game.Players:GetPlayerFromCharacter(hit.Parent)
    if not debounce then
        debounce = true
if user.TeamColor == game.Teams.Mayhem.TeamColor
then script.parent.mayhemonhill.Value = 1
if script.Parent.mayhemonhill.Value == 1
then wait(1)
part.BrickColor = user.TeamColor

and so on, if 2 mayhem people are on the point then make function again with 2 people and the wait time as 0.5!

I personally think the capture time should be longer, but that's you. If something does not work in my script, that's because i just jotted my idea down, and if you want the whole script, I would love to help if you want, and I am a somewhat seasoned scripter myself. We can work something out, and if not, just try something similar to this script. And remember, values do wonders on your games.

1 comment

0

Nice indentation.

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