Hello, I’m working on a beam system and I’m having some issues with the Damaging System, I’m currently trying to use .Touched and if you just keep the end part still it will only do damage, to do the constant damage you have to constantly move it on the character and that’s not really how I wanted it. I’ve tried doing touching parts but I’m doing the beam movement on the client so it didnt end up working, so I’m wondering if there is any other ways that would be possible to do?
When you activate the beam, fire a remote so the beam gets created on the server, touched event will work fine after it, just add a Debounce so it doesn’t install kill them
I’m not asking how to make the actual beam , that system is already in place which what you just said.
What I need help with is if you put your mouse on a character and dont move it, it will only work once, just how if you add a touched event to a part and just stand still it will only do it once.
Add a Debounce, i said that, you want it to only damage once so never set the Debounce back to false
What type of script is the one that you are having issues with?
It’s not about the system, it’s about the touched event. I have the debounces how I want them, let me get a video.
https://gyazo.com/bb52d86e912abe481239a8322169fe41
You see, if you simply stop it doesn’t fire anymore.
I dont really get it, what do you exactly want from this?
This is the script.
script.Parent.Touched:Connect(function(h)
print(h)
end)
And this is just the script made for the problem I’m having, I’m asking why its only firing if I’m moving on the part, and what the alternative would be?
Oooooh i understand you now, you want the touched event to fire even if the player is standing?
Have you tried using a while loop maybe?
Yes thats what I’m trying to figure out.
What would it be looping for? I dont want it to be every second it only needs to go when someone is touching the part.
You need to use Region3 (as a hotbox for the beam)
And to find the player do
Workspace:GetPartsInRegion3(yourRegion)
It will return a table, loop through it if its a part of a player then damage him, make sure to add Debounce for each player by himself so he can damage others but not the same players, before waiting a bit
This won’t work because the movement of the beam part is changing on the client and the damaging would be on my server script, this is to reduce lag for everyone and leave it more on each player themself.
You will create the region LOCALLY and the check LOCALLY but the damaging to the server
You could put an if statement inside the while loop, if you want it to constantly do damage when someone is touching the part. Other than that, I am not sure.
This will print “yes” every frame if the part is touching something
local BasePart = script.Parent
local IsTouching = false
BasePart.Touched:Connect(function()
IsTouching = true
end)
BasePart.TouchEnded:Connect(function()
IsTouching = false
end)
while true do
task.wait()
if IsTouching then
print("yes")
end
end
I need to be able to manage the touching parts so how would I get them using this way?
If you’re trying to do what I think you are, I’m sorry to disappoint but touched only fires when something starts touching something else.
You may however want to look into WorldRoot:ArePartsTouchingOthers and more likely BasePart:GetTouchingParts as one/both of these may be what you’re looking for
From what I could infer from the thread so far, I threw this together.
-- Kinda dodgy as it may break if TouchEnded doesn't fire properly. But effective till that happens.
local Players = game:GetService("Players");
local RunService = game:GetService("RunService");
local Touching = {}
local TouchingPlayer = nil
local TouchingCharacter = nil
local TouchingHumanoid = nil -- The most important variable here.
local DamagePart = script.Parent; -- The beam part.
local DamagePerSecond = 30; -- Damage over a 1 second period. Set to whatever you'd like.
DamagePart.Touched:Connect(function(Hit) -- Detect when the beam hits something else.
if table.find(Touching, Hit) then return end
table.insert(Touching, Hit)
if Hit.Parent:IsA("Model") then -- Is the Hit parented to a model?
local Player = Players:GetPlayerFromCharacter(Hit.Parent) -- Is that model a Player's character?
if Player then
TouchingCharacter = Player.Character
TouchingPlayer = Player
TouchingHumanoid = TouchingCharacter:FindFirstChildOfClass("Humanoid")
end
end
end)
DamagePart.TouchEnded:Connect(function(Hit)
if not table.find(Touching, Hit) then return end
table.remove(Touching, table.find(Touching, Hit))
if TouchingPlayer and Hit:IsDescendantOf(TouchingCharacter) then
task.defer(function() -- Defer because the call to TouchEnded may fire before the next limb is touched.
local StillTouching = false
for Index,Part in pairs(Touching) do
if Part:IsDescendantOf(TouchingCharacter) then
StillTouching = true
break -- No need to continue the loop.
end
end
if not StillTouching then
TouchingPlayer = nil
TouchingCharacter = nil
TouchingHumanoid = nil
end
end)
end
end)
-- Set up damage loop
local DoDamage = RunService.Heartbeat:Connect(function(DeltaTime) -- We need DeltaTime for that "Damager over 1 second period" effect.
if not TouchingCharacter then return end -- If there's no touching character there's no point in continuing.
if not TouchingHumanoid then return end -- If there's no humanoid there's definitely no point in continuing.
TouchingHumanoid.Health -= DamagePerSecond*DeltaTime -- Subtract DamagePerSecond * Deltatime. at 60 fps with 30 damage per second, this is roughly 0.5 HP.
if TouchingHumanoid.Health <= 0 then -- In the case of the Humanoid dying,
Touching = {} -- clear touching parts
TouchingPlayer = nil -- Clear touching player
TouchingCharacter = nil -- Clear touching character
TouchingHumanoid = nil -- Clear humanoid.
end
end)
-- And that's it, I think.
-- Let me know if there's any issues.