I’m currently making a JoJo game, and I have this small problem.
There’s this thing called “Timestop” which freezes other players in the game besides yourself.
My problem is, when you timestop, you don’t damage other players whenever you use any moves that uses your fists. Projectiles do damage, however.
function onTouched(part)
if script.Parent.Parent.BarrageValue.Value == true then
local h = part.Parent:FindFirstChild("Humanoid") -- the player to damage
local ignore = script.Parent.Parent.Parent.Humanoid --ignore the player attacking
if h then
if ignore ~= h then
wait()
h:TakeDamage (4.5)
end
end
end
end
script.Parent.Touched:connect(onTouched)
I’m not so sure why this is happening, this same script used to work in one of my past games but now it isn’t
Well, try using another way to freeze players. controls work well
local controls = require(game.Players.LocalPlayer.PlayerScripts:WaitForChild("PlayerModule")):GetControls()
controls:Disable() -- disable player movement
controls:Enable() -- enable them again
Honestly, I don’t know if that would work or not, but it’s worth giving a try
Also, try removing the h.TakeDamage part and change it to something like h.Health = h.Health - 4.5. Some say TakeDamage is not that reliable, although i’m not entirely sure.
Would that also freeze their whole character? I’m assuming disabling their controls only prevents them from walking, what I’m trying to achieve for frozen players is as if they actually froze like in the anime
which is why i anchor all the bodyparts of a player
(Like this gif)
Also, ive tried subtracting their health instead of :TakeDamage(), doesn’t work either sadly
Well, every single part is anchored (during timestop). I’ve actually damaging an npc that i inserted from the rig builder, and only one part was anchored (the humanoidrootpart) and the same results happened, no damage
Did the touched event fire when the freezed player is trying to attack? It could be that TakeDamage is not working. Insert a print statement or something.
the h is defined in another part of the script, so try using this:
function onTouched(part)
local h = part.Parent:FindFirstChild("Humanoid") -- the player to damage
if script.Parent.Parent.BarrageValue.Value == true then
local ignore = script.Parent.Parent.Parent.Humanoid --ignore the player attacking
if h then
if ignore ~= h then
wait()
h:TakeDamage (4.5)
end
end
end
end
script.Parent.Touched:connect(onTouched)
Well, I think @Aaroncy purposely put that h variable inside the if statement. If so, you can do this:
function onTouched(part)
local h
if script.Parent.Parent.BarrageValue.Value == true then
h = part.Parent:FindFirstChild("Humanoid") -- the player to damage
-- rest of the code
Don’t use Touched. Touched is for intersections caused by physics. Anchoring removes a part from physics simulation. If both parts in the interaction are anchored or not registered as a physical intersection, they are not considered touching.
You should instead use a method that checks for the nearest available player in some sort of method that works based on the position of the stand. There are three ways I can think of for this:
Standard vector equation. Calculate the magnitude of the distance vector between your stand and your victims. Hurt the nearest one while the punch action is enabled. You can then add extras, such as making the stand point towards the victim.
Region-based find. Create a region around the stand that serves as the damage range. After casting to the region, find all characters from the fetched parts such that you don’t receive any duplicates, then damage each one. This, or repeat 1.
Raycast. When the punch action is enabled, cast a ray in front of the stand a few studs forward and attempt to look for a hit character. If one is found and you can retrieve the Humanoid, apply damage.
These are all effective ways to disassociate your system with physics and not rely on the engine to determine if your parts have physically intersected or not. Compared to your current code as well (an undebounced touch event), these would also be relatively ideal for performance.
the touched event not working because its anchored, i recommend using Region3, since im also making a jojo game and i use region3 for the hitbox.
region3 is the same as touched event the only difference is it can detect any part inside it,
no matter if it’s invisible or anchored, you can also change the size to whatever you want!
which means it’s a lot better than touched, but for projectile i still recommend using touched since its easier.
Example of Region3 :
local Size = Vector3.new(10,10,10) -- the size of the hitbox
local Position = YourStand.PrimaryPart.CFrame * CFrame.new(0,0,-2) -- this will make a hitbox in front of your stand
local StandOwnerCharacter = YourStand.Owner.Value -- I don't know how you get the Character but in my game i add an ObjectValue into the stand to knows who its owner is
local region = Region3.new(Position - (Size/2),Position + (Size/2)) -- makes the region3
local hit = workspace:FindPartsInRegion3(region,StandOwnerCharacter,math.huge)
-- now we're gonna get all the parts inside the region3 and add some checking
for i,v in pairs(hit) do
if v.Parent:FindFirstChildWhichIsA("Humanoid") then
if not v.Parent:FindFirstChild(StandOwnerCharacter.Name.."Checks") then
local check = Instance.new("BoolValue",v.Parent)
check.Name = StandOwnerCharacter.Name.."Checks"
game.Debris:AddItem(check,0.1)
v.Parent.Humanoid:TakeDamage(10)
end
end
end