|
| 09 Jan 2016 06:50 PM |
how would I :Destroy() The fire part from workspace? regardless if it hits a player.
repeat coroutine.yield() until game.Players.LocalPlayer.Character
local player = game.Players.LocalPlayer local char = player.Character function GetBullet() local p = game.ReplicatedStorage.Main.Projectiles.Fire:Clone() p.CanCollide = false p.Parent = game.Workspace Instance.new("BodyVelocity",p) return p end script.Parent.Equipped:connect(function(mouse) mouse.Button1Down:connect(function() local mH = mouse.Hit local bullet = GetBullet() bullet.CFrame = script.Parent.Handle.CFrame * CFrame.new(char.Torso.CFrame.lookVector * 2) bullet.CFrame = CFrame.new(bullet.Position, mH.p) bullet.BodyVelocity.velocity = bullet.CFrame.lookVector * 120 wait(5)
bullet.Touched:connect(function(hit) local humanoid = hit.Parent:FindFirstChild("Humanoid") local name = player.Character.Name if humanoid then if hit.Parent.Name ~= name then humanoid:TakeDamage(10)
end end end) end) end)
#code --[[wot]]-- |
|
|
| Report Abuse |
|
|
|
| 09 Jan 2016 06:58 PM |
testing your sig
#code decryptme /---./--/..--/..//-.// |
|
|
| Report Abuse |
|
|
|
| 09 Jan 2016 07:33 PM |
| Call :Destroy() on the part when you need to destroy it. |
|
|
| Report Abuse |
|
|
|
| 09 Jan 2016 09:49 PM |
Thats what I did...but I cant seem to get it to work, I want it to happen after 5 seconds, regardless if it hits anything I havent managed to do it.
#code --[[wot]]-- |
|
|
| Report Abuse |
|
|
|
| 09 Jan 2016 09:53 PM |
| Fire a Remote Event to destroy it. |
|
|
| Report Abuse |
|
|
|
| 09 Jan 2016 09:54 PM |
Isnt it possible to do it within the script...? because Its going to be multiple parts...
#code --[[wot]]-- |
|
|
| Report Abuse |
|
|
|
| 09 Jan 2016 10:01 PM |
| Does the output say anything? If not, add a print() on every line to see where it stops (with :Destroy() included). |
|
|
| Report Abuse |
|
|
|
| 09 Jan 2016 10:06 PM |
it gets to swag 2 and cant go any further
repeat coroutine.yield() until game.Players.LocalPlayer.Character
local player = game.Players.LocalPlayer local char = player.Character function GetBullet() p = game.ReplicatedStorage.Main.Projectiles.Fire:Clone() p.CanCollide = false p.Parent = game.Workspace Instance.new("BodyVelocity",p) return p end script.Parent.Equipped:connect(function(mouse) mouse.Button1Down:connect(function() local mH = mouse.Hit local bullet = GetBullet() bullet.CFrame = script.Parent.Handle.CFrame * CFrame.new(char.Torso.CFrame.lookVector * 2) bullet.CFrame = CFrame.new(bullet.Position, mH.p) bullet.BodyVelocity.velocity = bullet.CFrame.lookVector * 120 print("swag")
bullet.Touched:connect(function(hit) local humanoid = hit.Parent:FindFirstChild("Humanoid") local name = player.Character.Name if humanoid then print("swag2") if hit.Parent.Name ~= name then humanoid:TakeDamage(10) p:Destroy() print("swag5") end end end) end) end)
it gets to swag 2 and cant go any further
#code --[[wot]]-- |
|
|
| Report Abuse |
|
|
|
| 09 Jan 2016 10:11 PM |
Try this.
"if (hit.Parent.Name ~= name) then" |
|
|
| Report Abuse |
|
|
|
| 09 Jan 2016 10:13 PM |
that still only removes if the it hits a player...I want it to remove regardless.
#code --[[wot]]-- |
|
|
| Report Abuse |
|
|
|
| 09 Jan 2016 10:15 PM |
| In that case, use a coroutine. Make the coroutine wait five seconds. After that, check to see if the bullet still exists. If it does, call Destroy() on the bullet. |
|
|
| Report Abuse |
|
|
|
| 09 Jan 2016 10:16 PM |
Im a noob I dont understand...sorry.
#code --[[wot]]-- |
|
|
| Report Abuse |
|
|
|
| 09 Jan 2016 10:18 PM |
| In that case, take a look at this. http://wiki.roblox.com/index.php?title=Beginners_Guide_to_Coroutines |
|
|
| Report Abuse |
|
|
|
| 09 Jan 2016 10:26 PM |
local newThread = coroutine.wrap(function() p:Destroy() end) newThread()
would that work?
#code --[[wot]]-- |
|
|
| Report Abuse |
|
|
mudkip99
|
  |
| Joined: 17 Jun 2008 |
| Total Posts: 3362 |
|
|
| 09 Jan 2016 10:27 PM |
Alternately, add the part to the debris service like this:
local debris = game:GetService("Debris")
debris:AddItem([item], [lifetime])
The debris service will then automatically remove [item] after [lifetime] seconds has passed, no coroutines required. |
|
|
| Report Abuse |
|
|
|
| 09 Jan 2016 10:29 PM |
can It be used in any part of the script or in a specific place?
like
local debris = game:GetService("Debris")
debris:AddItem(P, 5)
#code --[[wot]]-- |
|
|
| Report Abuse |
|
|
mudkip99
|
  |
| Joined: 17 Jun 2008 |
| Total Posts: 3362 |
|
|
| 09 Jan 2016 10:29 PM |
| forgot to mention, if you leave the lifetime variable out of the AddItem() call, it will default to ten seconds. http://wiki.roblox.com/index.php?title=API:Class/Debris |
|
|
| Report Abuse |
|
|
mudkip99
|
  |
| Joined: 17 Jun 2008 |
| Total Posts: 3362 |
|
|
| 09 Jan 2016 10:32 PM |
the debris variable is just to hold a reference to the service, you can put that anywhere before you use it (but ideally, grouped together with your other variable for easeir organization)
You don't call debris:AddItem() until you want the object added to the debris service, as it will begin the countdown immediately. |
|
|
| Report Abuse |
|
|
|
| 09 Jan 2016 10:38 PM |
local debris = game:GetService("Debris")
repeat coroutine.yield() until game.Players.LocalPlayer.Character
local player = game.Players.LocalPlayer local char = player.Character function GetBullet() local p = game.ReplicatedStorage.Main.Projectiles.Fire:Clone() p.CanCollide = false p.Parent = game.Workspace Instance.new("BodyVelocity",p) return p end script.Parent.Equipped:connect(function(mouse) mouse.Button1Down:connect(function() local mH = mouse.Hit local bullet = GetBullet() bullet.CFrame = script.Parent.Handle.CFrame * CFrame.new(char.Torso.CFrame.lookVector * 2) bullet.CFrame = CFrame.new(bullet.Position, mH.p) bullet.BodyVelocity.velocity = bullet.CFrame.lookVector * 120 wait(5)
bullet.Touched:connect(function(hit) local humanoid = hit.Parent:FindFirstChild("Humanoid") local name = player.Character.Name if humanoid then if hit.Parent.Name ~= name then humanoid:TakeDamage(10)
end end end) end) end)
debris:AddItem(p, 6
#code --[[wot]]-- |
|
|
| Report Abuse |
|
|
|
| 09 Jan 2016 10:39 PM |
| Wouldn't it still cause the script to wait though, mud? |
|
|
| Report Abuse |
|
|
mudkip99
|
  |
| Joined: 17 Jun 2008 |
| Total Posts: 3362 |
|
|
| 09 Jan 2016 10:41 PM |
| The debris service is asynchronous, so it will run independently of any other scripts and doesn't cause a wait. |
|
|
| Report Abuse |
|
|
|
| 09 Jan 2016 10:44 PM |
| Oh, I never knew that before. Interesting. |
|
|
| Report Abuse |
|
|
|
| 09 Jan 2016 11:09 PM |
Having a really hard time trying to implement this into debris....
Someone help me, I'm a complete utter noob. ;-;
repeat coroutine.yield() until game.Players.LocalPlayer.Character
local player = game.Players.LocalPlayer local char = player.Character function GetBullet() p = game.ReplicatedStorage.Main.Projectiles.Fire:Clone() p.CanCollide = false p.Parent = game.Workspace Instance.new("BodyVelocity",p) return p end script.Parent.Equipped:connect(function(mouse) mouse.Button1Down:connect(function() local mH = mouse.Hit local bullet = GetBullet() bullet.CFrame = script.Parent.Handle.CFrame * CFrame.new(char.Torso.CFrame.lookVector * 2) bullet.CFrame = CFrame.new(bullet.Position, mH.p) bullet.BodyVelocity.velocity = bullet.CFrame.lookVector * 120 print("swag")
bullet.Touched:connect(function(hit) local humanoid = hit.Parent:FindFirstChild("Humanoid") local name = player.Character.Name if humanoid then print("swag2") if hit.Parent.Name ~= name then humanoid:TakeDamage(10) p:Destroy() print("swag5") end end end) end) end)
#code --[[wot]]-- |
|
|
| Report Abuse |
|
|
mudkip99
|
  |
| Joined: 17 Jun 2008 |
| Total Posts: 3362 |
|
|
| 09 Jan 2016 11:17 PM |
I'm not 100% sure this will work, but it -should- if I'm understanding how your code is set up
local player = game.Players.LocalPlayer local char = player.Character local debris = game:GetService("Debris") -- Get the debris service
function GetBullet() p = game.ReplicatedStorage.Main.Projectiles.Fire:Clone() p.CanCollide = false p.Parent = game.Workspace Instance.new("BodyVelocity",p) return p end script.Parent.Equipped:connect(function(mouse) mouse.Button1Down:connect(function() local mH = mouse.Hit local bullet = GetBullet() bullet.CFrame = script.Parent.Handle.CFrame * CFrame.new(char.Torso.CFrame.lookVector * 2) bullet.CFrame = CFrame.new(bullet.Position, mH.p) bullet.BodyVelocity.velocity = bullet.CFrame.lookVector * 120 debris:AddItem(bullet, 5) -- Add the bullet to debris
print("swag")
bullet.Touched:connect(function(hit) local humanoid = hit.Parent:FindFirstChild("Humanoid") local name = player.Character.Name if humanoid then print("swag2") if hit.Parent.Name ~= name then humanoid:TakeDamage(10) p:Destroy() print("swag5") end end end) end) end)
|
|
|
| Report Abuse |
|
|
mudkip99
|
  |
| Joined: 17 Jun 2008 |
| Total Posts: 3362 |
|
|
| 09 Jan 2016 11:19 PM |
Also, it would probably be a good idea to change
p = game.ReplicatedStorage.Main.Projectiles.Fire:Clone()
into
local p = game.ReplicatedStorage.Main.Projectiles.Fire:Clone() |
|
|
| Report Abuse |
|
|