How do I make a “king of the hill” script?

Hi again, I’m Crrustyy. I am thinking about how I can make a king of the hill script, but have no idea where to start. Here is what I am looking to do.

  1. Make a part that when touched, it makes a GUI appear over the players head.

  2. Make the GUI have a timer to see how long each player has been the King of the Hill. And when the player leaves the part, the timer stops, and resumes when they re enter the part.

  3. when the timer of the round ends, the player with the most time in the part, wins.

This is far too complicated for me, but would be handy to know for future games!

Any suggestions? Please let me know!

Many thanks!

Crrustyy

If it is easier for you, message me on discord TaylorOnShow#0447

3 Likes

Why do you keep removing the post?

I’m almost done, I just keep accidentally posting it.

Ohh ok, sure, just take all the time you need :slight_smile:

You can’t ask scripts in the forum, that’s not how this category works. Here is the link:
https://devforum.roblox.com/t/about-the-scripting-support-category/45863/2

There is nothing there about asking for help to understand how to do it. I am only asking where to start. :slight_smile:

My friend @TheeDeathCaster (pinging to get his input) actually made exactly this. I believe the way he did it was creating a Region3 out of an invisible part at the top of the hill. The GUI part I am not sure, but he did do that too.

Ok. I am not familiar with region3, but I’ll look into it!

A simple solution would be to use a while wait(1) do and then check if the player is colliding with an invisible hill part. The over head gui could just be a BillboardGUI with a studsoffset of 0, 2, 0 in the players head with the score

This would work but it isn’t the best solution.
Region3 would be better

2 Likes

I highly suggest using region3 for something like this (Link to lua site here)

Using Region3, it creates an invisible area in which a function can occur in. I would use a while __ do loop to keep checking if players enter the region.

I don’t know if this will help you any , but the following code detects where the part by the name of “Region” is and then creates an invisible region right ontop of the part.

local Region1 = Region3.new(Vector3.new(game.Workspace.Region.Position)-Vector3(game.Workspace.Region.Size/2,Vector3.new(game.Workspace.Region.Position)+Vector3(game.Workspace.Region.Size/2)

(Basically what this does is it gets the top right corner of the part and the bottom left corner of the part and says any distance between the 2 is the bound region)

Then in the loop, do what @Courageous_Canister suggested and have a billboard GUI pop up above their head that increases by 1 every second that they are inside the region (or the part if you use the variable “Region1” that I posted)

EDIT: I HIGHLY recommend you watch this youtube video from @SteadyOn , It helped me get a better understanding about regions https://www.youtube.com/watch?v=qOhZi1jUEvI

Also the following might help:

:FindPartsInRegion3()

:FindPartsInRegion3WithIgnoreList()

3 Likes

I will! Thanks for the reply! It really helps!

@incapaxx Hewwo it is I.
@Crrustyy The way I accomplished my king of the hill was by taking the location and size of the part location and checking if the player’s torso was in range. As for the GUI part, I used a Hint object (they’re deprecated, so probably not the best to use now).

An example of how I got the player from being within the Y range’s the below:

if ((PlayerPosition.Y <= HillLocation.Position.Y + HillLocation.Size.Y / 2) and (PlayerPosition.Y >= HillLocation.Position.Y - HillLocation.Size.Y / 2) then
...

Probably not the best way, but it got the job done. As per the GUI for who was on longest, I had a IntValue that kept track and was added onto when a player was on the hill.

Hope this helped. :slight_smile:

2 Likes

Careful with values :stuck_out_tongue: unless they are client-sided, a lot of them are exploitable, I try to keep everything in a script in SSS, just so I know the values wont be hacked.
(The hacker would have to be really low to wanna hack a king of the hill timer but you never know)

But this is a much simpler way to do the king of the hill if you don’t feel like learning region3 !

2 Likes

No worries. The position check and the timer were handled by the server, so they should be pretty secure from pesky exploiters (however, this wont stop exploiters from “teleporting”). :stuck_out_tongue: I’m not sure if this’s off topic, apologies if so.

2 Likes