Hello!
I am currently making a tool that makes someone take damage if you click on them with it.
Inside of the tool is a script and a local script, which uses a remote event stored in replicated storage to communicate back and forth.
All of the code seems to work, however there is one dilemma: when you click someone else, the tool damages yourself instead of the player you clicked.
Here is my code:
Here is the local script:
local player = game.Players.LocalPlayer
local tool = script.Parent
local mouse = player:GetMouse()
tool.Activated:Connect(function()
local target = mouse.Target
if target.Parent:FindFirstChild("Humanoid") then
game.ReplicatedStorage.Damage:FireServer(target)
else
end
end)
Finally, here is the normal script:
game.ReplicatedStorage.Damage.OnServerEvent:Connect(function(target)
print("Recieved")
local humanoid = target.Character.Humanoid
print(humanoid.Parent)
humanoid.Health = humanoid.Health - 10
print("Health reduced")
end)
I’ve tried looking everywhere, but I can’t find a good solution.
Can anyone help?
Thanks!