Alright so im trying to make a combat system or something. and im trying to make a script where if you click. the script checks if the thingy the tool hit was a player, and if it was a player. then it deals damage. heres the damage
local tool = script.Parent
local mouse = game.Players.LocalPlayer:GetMouse()
tool.Equipped:Connect(function()
mouse.Button1Down:Connect(function()
– the thingy im tryna figure out
end)
end)
16 Likes
Do you want the script to check if you click on a player, or if your physical tool touches the player?
5 Likes
if my physical tool touches the player.
5 Likes
Can you show me the tool and it’s children in a screenshot so I can help you better?
5 Likes
the “event” script is the script where is the thingy im tryna make
5 Likes
great english btw (very great)
5 Likes
Do you want to detect if Fist2, Handle, or both, touches the part?
5 Likes
both. (because fist2 is like it sounds, the second fist. and the handle is the first fist
5 Likes
god damn my english is pretty bad lol.
2 Likes
Every Tool has a Handle in it, the part. You can simply check the distance between the players.
A Touched function wouldn’t be very efficient because it’s buggy.
Try this:
task.wait(5)
while task.wait(0.05) do
for _,character in pairs(workspace:GetChildren()) do
if (character.HumanoidRootPart.CFrame.Position-Tool.Handle.CFrame.Position).Magnitude <= 3 then
character.Humanoid:TakeDamage(1)
end
end
end
Every 0.05 seconds, it checks every single character in-game, and checks if the distance between the character and the tool is 3 studs or below, then it deals 1 damage per that 0.05 seconds if in that radius.
4 Likes
lemme try it. (i hate the 30 text thingy)
2 Likes
You could also do:
local tool = script.Parent
local mouse = game.Players.LocalPlayer:GetMouse()
local Fist1 = tool.Fist1 --Indexing Handle/Fist1
local Fist2 = tool.Fist2 --Indexing Fist2
tool.Equipped:Connect(function()
mouse.Button1Down:Connect(function()
Fist1.Touched:Connect(function(hit) -- checks if fist1 is touched (hit is the part it touched)
if hit.Parent:FindFirstChild("Humanoid") then
--Code that fires when touched
end
end)
Fist2.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then --checks if fist2 is touched (hit is the part it touched)
--Code that fires when touched
end
end)
end)
end)
The script checks if the fists touch another player, and then runs the code inside the .Touched function. It still works.
7 Likes
I wouldn’t use a Touched event, because it’s very inconsistent, especially if you’re doing a combat game.
4 Likes
oh yeah i got 1 thingy to do, because what im also trying to figure out is how to deal damage. because in the script it says " --Code that fires when touched" but i don’t have the code. so thats what im tryna figure out.
4 Likes
I already did that for you. I ran :TakeDamage()
on the Humanoid. Run my code, it’ll work.
4 Likes
Then you would replace that part with:
hit.Humanoid:TakeDamage(AmountOfDmgHere)
3 Likes
i know but for some reason the dummies are randomly stuck under the ground and i cant test the thingy on em
3 Likes
Invite a friend. Do you need me to test it?
4 Likes
Raise the dummies up in studio, simple…?
3 Likes