Damage loop ClickDetector script no longer doing damage to the player

A while ago I asked how I would go about damaging a player via a ClickDetector. This was the (functioning) script someone so kindly helped me make:

local Part = script.Parent
local ClickDetector = Part:WaitForChild("ClickDetector")
	local char = Player.Character
	local hum = char:FindFirstChild('Humanoid')
	if hum == nil then return end

		hum:TakeDamage(10) --amount it damages per loop
		task.wait(5) --time it waits per loop
	until hum.Health <= 0

EDIT: it didnt paste the variables for some weird reason. anyway.

However, as my scripts like to mysteriously do, this recently broke for no discernable reason. It doesn’t output any errors into Output. It just no longer damages the player.

Did something in here get deprecated? How do I get this working again?


1 Like

None of the functions in your script were deprecated so everything should work. Could you paste your entire script though?

1 Like

What I posted is the whole script.

Very old code.

	local __CHARACTER = __PLAYER.Character
	local __HUMANOID = __CHARACTER:FindFirstChildOfClass("Humanoid")
	if __HUMANOID ~= nil then
      --could use task.spawn() but eh
			until __HUMANOID.Health <= 0

So, you need to do a few things.

  • Add a Remote Event named DamagePlayer (Place in ReplicatedStorage)
  • Make leaderstats, You can even make the PlrList Enum, but in order to make it work you need leaderstats.

Now, put this script in the ClickDetector.

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEvent = ReplicatedStorage:WaitForChild("DamagePlayer")

local ClickDetector = script.Parent


Now, Put this script inside the RemoteEvent.

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEvent = ReplicatedStorage:WaitForChild("DamagePlayer")

	local leaderstats = player:WaitForChild("leaderstats")
	local health = leaderstats:WaitForChild("Health")
	health.Value = health.Value - 10

If you dont have leaderstats, Use this script and put it in ServerScriptService:

	local stats = Instance.new("Folder", plr)
	stats.Name = "leaderstats"
	local Cash = Instance.new("IntValue", stats)
	Cash.Name = "Cash" -- The name that will be displayed on the leaderboard
	Cash.Value = 0 -- How much you start with

If this helps, Great, else let me know.

there are soooo many flaws with that code

Why use events for mouseclick?? this is very exploitable.

Add an anticheat system. That should do the trick.

How did you reference the ClickDetector then?

Your code works for me. So your issue may lie within your Explorer.

What if you provided images of your Explorer?

This may not be the issue, however a LocalScript that is a descendant of the workspace will not run, unless it is in a Tool or Character.

Woops. For some reason it didn’t paste the variables. Lemme edit the original post.

Why are you using RemoteEvents and Leaderstats though… you don’t need either of these. MouseClick returns the Player who clicked it, so why do literally any of this.

Nah, I don’t think this is the issue, considering this script worked before.
Here it is anyway. Very simple, dunno what you expected.
Screen Shot 2023-01-22 at 2.24.38 PM

ough… i can SEE the age on this one.
Anyway, this works. What on earth am I doing wrong in my original then.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.