I am making a king of the hill game and am new to scripting [please help]

Hello all, I am currently working on a king of the hill game (KOTH) and I cannot find tutorials on how to script it. What I would like to achieve is a cylinder 0.2 studs above the ground, when you step on it I would like it to give you points for every second that you stand on it.

Pic:

1 Like

– In a server script you put inside the pad.

script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild(“Humanoid”) then
local chr = hit.Parent
local plr = game.Players:GetPlayerFromCharacter(chr)
while wait(1) do
plr.leaderstats.Points.Value = plr.leaderstats.Points.Value + 1
end
end
end)

–Try this

2 Likes

Would the script be put into the part itself, or something else?

1 Like

yes put it in the hill pad [Just need to get the post to 30 characters]

1 Like

testing…

you maybe need to debug the code a little writed it in studio

1 Like

ok so it doesn’t add anything to the leaderboard. or would I do that?

I would highly recommend not using touched, due to it having a debounce and a chance not to trigger
Also that script would make it where just by touching, they would gain points indefinitely

Here is my suggestion, you should use magnitude

Simply insert a script into the cylinder.

local hill = script.Parent
local range = tonumber(script.Parent.Size.Y)

while true do -- A loop that fires every second
   for i,v in ipairs(game.Players:GetPlayers()) do -- This goes through all the players
      if v.Character ~= nil and v.Character:FindFirstChild("Torso") then -- Checks to make sure the players are spawned in and finds the torso. Upper or Lower torso for R15
         if (v.Character:FindFirstChild("Torso").Position - hill.Position).Magnitude <= range then --Check to make sure it is within range
            v:FindFirstChild('leaderstats'):FindFirstChild("CoinNameHere").Value = v:FindFirstChild('leaderstats'):FindFirstChild("CoinNameHere").Value+ 1 -- Adds points
         end
      end
   end
   wait(1)
end
4 Likes

Use humanoidrootpart instead of torso becouse else it won´t work on R15

1 Like

I am just saying this, we do not make scripts for you, we do help fix scripts though.

2 Likes

If you plan on making a more complicated game, then instead of just learning for this particular use, I would delve into Part.Touched and also learn how to configure values (that could be placed inside ReplicatedStorage) depending on what’s happening while the Part is touched. For now 4Ive’s script seems like an okay idea, but make sure that you first create the leaderstat. More information how how to do that can be found here. Later on, I personally stop using leaderstats all together and instead create player folders for each player and in there store a value, since it’s much more easy to configure in my opinion. Most people disagree though.