Yes, it does! Thank you so much! If you don’t mind, can you please tell me how this works? I don’t understand my own code much myself.
oh, there are still a couple of issues:
1.) 14:31:49.411 ServerScriptService.Hollow Purple Server:258: invalid argument #1 to ‘remove’ (table expected, got number) - Server - Hollow Purple Server:258
and at the end of the code I have game.Debris:AddItem(purple, 10)
but I think heartbeat keeps running and gives me error that Inner
is not a valid member of model.
Sure!
The alreadyHit
list is used to store all of the characters that have already been hit with the hollow purple.
Then, we loop through the purpleHitContents
every heartbeat.
This loop assumes that every single part that is hit is part of a player’s character, at first. This means that we can use local humanoid = char:FindFirstChild("Humanoid")
to see whether our assumption is correct or not.
If humanoid
exists, and we haven’t already damaged the character (checked using the alreadyHit
table), then we go ahead and damage the humanoid
, while also adding the character to the alreadyHit
list, so they don’t get hit with the same move multiple times.
Finally, we wait a little bit, and then we remove the player from the alreadyHit
table, so that if the move is used again, they will not be immune to it.
Is there any part you would like me to expand on?
Ah, thats my bad. I’ll edit the script to fix the issue!
No thank you, this is a great explanation of the code!
Another version of the script, but this time where the heartbeat stops after a certain amount of time:
local RunService = game:GetService("RunService")
local purpleOverlapParameters = OverlapParams.new() -- id highly suggest adding the player' character as a blacklist
local alreadyHit = {}
local connection = nil
connection = RunService.Heartbeat:Connect(function()
local purpleHitContents = workspace:GetPartBoundsInBox(purple.Inner.CFrame, purple.Inner.Size, purpleOverlapParameters)
for i, part in pairs(purpleHitContents) do
local char = part.Parent
local humanoid = char:FindFirstChild("Humanoid")
if humanoid and table.find(alreadyHit, char) == nil then
table.insert(alreadyHit, char)
humanoid:TakeDamage(250)
task.wait(4)
if table.find(alreadyHit, char) then
table.remove(alreadyHit, table.find(alreadyHit, char))
end
end
end
end)
task.wait(5) -- add however long you want the move to last for
if connection then
connection:Disconnect()
connection = nil
end
The thing is that at the end of the code the purple instance gets destroyed by being added to debris after a certain amount of time, and the player might not even use hollow purple again. I’m having trouble figuring out how I can use the heartbeat and stop it if it detects that there is no longer hollow purple in the game, and start again if it detects that hollow purple is in the game.
Oh nevermind, thats not an issue anymore.
However, why is this happening?
14:51:24.247 ServerScriptService.Hollow Purple Server:250: attempt to index nil with ‘FindFirstChild’ - Server - Hollow Purple Server:250
Line: local humanoid = char:FindFirstChild("Humanoid")
When the purple is added to Debris, use the connection:Disconnect()
line before it is deleted to stop the Heartbeat connection.
Something like this:
Debris:AddItem(purple, 5)
task.wait(4.5)
connection:Disconnect()
connection = nil
Does this solve the issues?
No, alreadyHit doesn’t doesn’t work (2 dummies with the same name still get destroyed) and there is still the same error
15:19:48.096 ServerScriptService.Hollow Purple Server:250: attempt to index nil with 'FindFirstChild' - Server - Hollow Purple Server:250
with this line local humanoid = char:FindFirstChild("Humanoid")
Solution:
local hits = {}
local function purpleGetInfo()
while purple do
task.wait(0.01)
local purplePosition = purple.Inner.Position
for i, hit in pairs(workspace:GetPartBoundsInRadius(purplePosition, 7)) do
print(hit.Parent.Name)
if hit.Parent:FindFirstChild("Humanoid") and hit.Name ~= player.Name then
if not hit.Parent.Humanoid:FindFirstChild(player.Name) then
if hits[hit.Parent.Name] then
return
end
hits[hit.Parent.Name] = true
hit.Parent:FindFirstChild("Humanoid"):TakeDamage(250)
wait(4)
hits[hit.Parent.Name] = false
end
end
end
end
end
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.