Well, you have some problems and missing components.
First, this is all local so you will only be damaging a player on your screen, but in reality, nothing is happening to them on the server's side.
I also don't see how you're getting a hold of the targeted players humanoid so I also believe you're missing that. I'll walk you through how to make it on the server's side, which will require a RemoteEvent and a ServerScript to be added.
Please keep in mind that I took the time to make a new LocalScript, along with a server script to guide you to what your goal is, so anything unfamiliar to you will be expected.
- Let's add a RemoteEvent in ReplicatedStorage and name it HealthDrainEvent
Now, the LocalScript in StarterCharacterScripts will contain:
The LocalScript has been edited to use a key for it to activate instead, using UserInputService to retrieve the input from the player
local RP = game:GetService("ReplicatedStorage")
local UIS = game:GetService("UserInputService")
local HealthDrainDevent = RP:WaitForChild("HealthDrainEvent")
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local draining = false
local cooldown = 1
UIS.InputBegan:Connect(function(input, processed)
if input.UserInputType == Enum.UserInputType.Keyboard then
if input.KeyCode == Enum.KeyCode.E then
local target = mouse.Target
if target.Parent.Humanoid or target.Parent.Parent.Humanoid then
local TargetHumanoid = target.Parent.Humanoid or target.Parent.Parent.Humanoid
if TargetHumanoid ~= player.Character.Humanoid then
print("Enemy humanoid detected, initiating doom.")
draining = true
while draining == true do
HealthDrainDevent:FireServer(TargetHumanoid)
wait(cooldown)
end
end
end
end
end
end)
UIS.InputEnded:Connect(function(input, processed)
if input.UserInputType == Enum.UserInputType.Keyboard then
if input.KeyCode == Enum.KeyCode.E then
draining = false
end
end
end)
and finally, add a ServerScript in ServerScriptService and put in the following:
local RP = game:GetService("ReplicatedStorage")
local HealthDrainEvent = RP.HealthDrainEvent
HealthDrainEvent.OnServerEvent:Connect(function(player, targetedHumanoid)
if targetedHumanoid.Health > 50 then
targetedHumanoid.PlatformStand = true
targetedHumanoid.JumpPower = 0
targetedHumanoid:TakeDamage(2)
else
targetedHumanoid.PlatformStand = false
targetedHumanoid.JumpPower = 50
end
end)
What you've been trying to achieve should now be working, make sure to alter it to your needs, for example, if you want them to press a key in order for it to activate instead of clicking. At the end of the day I hope this helps you out and if you have questions please add a comment below this answer.
3 comments
sorry im pretty new to scripting and you're so helpfull tysm :3
but what if i want it to be a keybind?
I'll edit it so it can do that.