|
| 26 Jun 2017 05:21 PM |
I have a script in a tool. When the player dies, the script gets deleted and stopps running. I need this script to run a few functions for an unknown amount of time after the death of the player. I could move this script somewhere safe, but how do I know when this script is finished? Is there a way to get information about the status of the script? Or is there another way to solve this? |
|
|
| Report Abuse |
|
|
Alexware
|
  |
| Joined: 07 May 2010 |
| Total Posts: 661 |
|
|
| 26 Jun 2017 05:23 PM |
it shouldn't disappear unless you instantly respawn... script status is literally in the order of the lines once it gets to the bottom line it's done add script:Destroy() to the bottom line to remove it when it's done. |
|
|
| Report Abuse |
|
|
helloburp
|
  |
| Joined: 26 Aug 2011 |
| Total Posts: 14376 |
|
| |
|
ahwz
|
  |
| Joined: 01 Apr 2010 |
| Total Posts: 3230 |
|
| |
|
|
| 26 Jun 2017 06:52 PM |
I want to know when the script has ended, not when the humanoid died. And the script is a bit more complicated, I have it spawn threads, and I dont know when they will finish. |
|
|
| Report Abuse |
|
|
|
| 27 Jun 2017 07:56 AM |
| Or is there a way to transfere or move the threads to another script? This would solve the problem too |
|
|
| Report Abuse |
|
|
BreggFast
|
  |
| Joined: 04 Jul 2016 |
| Total Posts: 14 |
|
|
| 27 Jun 2017 08:03 AM |
Debounce.
running = true
while running do
dowhatthescriptsays()
running = false
end
print("I am done")
something like that |
|
|
| Report Abuse |
|
|
|
| 27 Jun 2017 12:09 PM |
| And how exactly would debounce help me with this problem? |
|
|
| Report Abuse |
|
|
ad_zz
|
  |
| Joined: 11 Jun 2011 |
| Total Posts: 385 |
|
|
| 27 Jun 2017 12:31 PM |
| so u can check if the scripts still running |
|
|
| Report Abuse |
|
|
|
| 27 Jun 2017 01:03 PM |
The problem is, the script stops running when its deleted. how do I move the process/thread to another script, so it can continue? I could also move the entire script, but then I have to know when all the threads have ended to remove it |
|
|
| Report Abuse |
|
|
WXBZ
|
  |
| Joined: 10 Oct 2012 |
| Total Posts: 850 |
|
|
| 27 Jun 2017 01:59 PM |
That is because your script is in the character.
for _, post in pairs(game.Players.WXBZ.Posts:GetChildren()) do post.Signature.Text = 'scripters.cf' end |
|
|
| Report Abuse |
|
|
|
| 27 Jun 2017 01:59 PM |
wxbz is bad
This is an automated signatiure. Current project, GSR |
|
|
| Report Abuse |
|
|
WXBZ
|
  |
| Joined: 10 Oct 2012 |
| Total Posts: 850 |
|
|
| 27 Jun 2017 02:02 PM |
Fight me on the server.
for _, post in pairs(game.Players.WXBZ.Posts:GetChildren()) do post.Signature.Text = 'scripters.cf' end |
|
|
| Report Abuse |
|
|
JoshRBX
|
  |
| Joined: 19 May 2012 |
| Total Posts: 8778 |
|
| |
|
M_org
|
  |
| Joined: 19 Sep 2013 |
| Total Posts: 231 |
|
|
| 27 Jun 2017 02:30 PM |
cba to write code
- PlayerAdded event - add a character added event - find humanoid with char - check to see if dead - do all your fancy scripting
R$30 |
|
|
| Report Abuse |
|
|
| |
|
M_org
|
  |
| Joined: 19 Sep 2013 |
| Total Posts: 231 |
|
|
| 27 Jun 2017 02:33 PM |
@Lua,
I think .Changed only works for values...
R$30 |
|
|
| Report Abuse |
|
|
| |
|
|
| 27 Jun 2017 02:34 PM |
| I've had to use some weird things to get stuff done my friend, experimentation is amazing. |
|
|
| Report Abuse |
|
|
|
| 27 Jun 2017 02:42 PM |
game.Players.PlayerAdded:connect(function(player) player.CharacterAdded:connect(function(character) character:WaitForChild("Humanoid").Died:connect(function() -- here you can write what ever your function is, OR you can call another function here. end) end) end)
|
|
|
| Report Abuse |
|
|
|
| 27 Jun 2017 02:44 PM |
for example;
function onDead() print(2+2) end
game.Players.PlayerAdded:connect(function(player) player.CharacterAdded:connect(function(character) character:WaitForChild("Humanoid").Died:connect(function() onDead() end) end) end)
|
|
|
| Report Abuse |
|
|
|
| 27 Jun 2017 02:45 PM |
the function you called will continue running even if the original script gets deleted when the player respawns.
|
|
|
| Report Abuse |
|
|
|
| 27 Jun 2017 02:47 PM |
I know that the script is in the character, but I can move it somewhere else, thats no problem. The problem is: I want to delete this script, as soon as all the threads inside this script have finished.
with thread I mean:
spawn(function() --stuff end ) or
local newThread = coroutine.create(function() --stuff end ) coroutine.resume(newThread)
how do I know when all threads of one script have finished?
|
|
|
| Report Abuse |
|
|
|
| 27 Jun 2017 02:49 PM |
or, more efficient way you can put the function inside a modulescript located in scriptservice (for example)
the script in the tool would require that module, and call a function in the module when the player dies. the function will not stop even if the script is deleted because its located inside the module (which doesn't get deleted)
============================================
-- IN MODULE SCRIPT --
local module = {}
function module.onDead() print(2+2) end
return module
-- IN TOOL SCRIPT --
local module = require(game.ServerScriptService:FindFirstChild("ModuleScript"))
game:Players.PlayerAdded:connect(function(player) player.CharacterAdded:connect(function(character) character:WaitForChild("Humanoid").Died:connect(function() module.onDead() end) end) end)
|
|
|
| Report Abuse |
|
|
|
| 27 Jun 2017 02:51 PM |
@WeirdGuyHere
Is there a way to just start a block of code like this, so it continues after death, but started befor they died? |
|
|
| Report Abuse |
|
|