To make this easier to understand, here is code that should work as long as you have the following:
- a
Part
inside of the workspace called “Part” - the following code inside of a
ServerScript
in a suitable place - make sure the
leaderstats
is set up correct with the name “Wins” being spelt the exact same
since this is a ServerScript
, it’s unexploitable and will work without having to use RemoteEvents
local PlayerService = game:GetService("Players")
local Part = workspace.Part
local cooldownTable = {}
Part.Touched:Connect(function(otherPart)
if otherPart.Parent:FindFirstChild("Humanoid") then
local characterWhoTouchedPart = otherPart.Parent -- this represents the character who touched the part
if not table.find(cooldownTable, characterWhoTouchedPart.Name) then -- if the character has not touched the part, run the following code:
table.insert(cooldownTable, characterWhoTouchedPart.Name)
characterWhoTouchedPart.Humanoid.Health = 0
local playerWhoTouchedPartWins = PlayerService:GetPlayerFromCharacter(otherPart.Parent).leaderstats.Wins -- gets the wins of the player who touched the part
playerWhoTouchedPartWins.Value += 1 -- change this number depending on how many wins you want to give the player
task.wait(30) -- how ever long you want the cooldown time to last
table.remove(cooldownTable, table.find(cooldownTable, characterWhoTouchedPart.Name))
else
warn(characterWhoTouchedPart.Name.." is on cooldown!")
end
end
end)