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.
Make a part that when touched, it makes a GUI appear over the players head.
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.
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
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.
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
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)
@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.
Careful with values 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 !
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”). I’m not sure if this’s off topic, apologies if so.