So in order to know when the client clicks something lets say a food item to heal you'd need a local script to detect when they click right?

healEvent.OnServerEvent:Connect(function(player,heal)
--heals stuff here
end)

How would I prevent exploiters from firing this to achieve godmode? One method I can think of is limit the amount of times this can be fired by the player?


local playersHealed = {}

function ifHealed(player)
	for _,v in pairs playersHealed do
		if v = player.Name then
			return true
		end
	end
return false
end


healEvent.OnServerEvent:Connect(function(player,heal)
	local playerRecentlyHealed = ifHealed(player)

	if playerRecentlyHealed == false then
		table.insert(playersHealed,player.Name,1)
		player.Character.Humanoid.Health = player.Character.Humanoid.Health + 10
		wait(.5)
		table.remove(playersHealed,1)
	end
end)

Is there a better method to go about it? This method seems like it will delay instant full health healing, but the exploiter can still use it to heal 10 health every .5 seconds. If I made the wait longer it'd just force players to be able to eat food slower.

3 comments

0

oh wait for the table.remove(playersHealed,1) i'd have to make another function because if another player fired the event right after then it'd remove them from the ifHealed list first

0

in your case i would count how much food they have, i don't know how your food item structure looks like but you get the point, stats like food should be handled all on server, that way you can prevent him from eating infinitely.

0

I just realized that you can use the activated event on a server script too. Idk why I thought it was only allowed locally. This makes everything so much easier.