BOZZSYLUX
|
  |
| Joined: 05 Sep 2009 |
| Total Posts: 3567 |
|
|
| 15 Nov 2012 10:24 PM |
Hi I am pretty new to scripting (I draw stuff) and I need some help with a basic script.
function fire(player)
local sound = script.Parent:FindFirstChild("GunSound") if sound == nil then sound = Instance.new("Sound") sound.Name = "GunSound" sound.SoundId = "http://www.roblox.com/asset/?id=2101148" sound.Volume = 5 sound2.Parent = script.Parent sound2 = Instance.new("Sound") sound2.Name = "Rsound" sound2.SoundId = "http://www.roblox.com/asset/?id=2697432" sound2.Volume = 5 sound2.Parent = script.Parent end sound:play() wait(3) sound2:play() <--- This is line 35..
This is a pretty basic piece of code I have that eventually needs to represent as a cannon. The function needs to (when I click the fire button) play the first sound and after a 3 second delay play the 2nd sound. This is what output says;
Workspace.M102 105mm Cannon.Switch.FireGun:35: attempt to index global 'sound2' (a nil value)
I've tried asking a friend but he had to go and I wondered if the peepz on this forum section could be nice enough to explain me how I solve this little puzzle.
Air Marshal Bozz The RO-Force. |
|
|
| Report Abuse |
|
|
BOZZSYLUX
|
  |
| Joined: 05 Sep 2009 |
| Total Posts: 3567 |
|
| |
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
| |
|
BOZZSYLUX
|
  |
| Joined: 05 Sep 2009 |
| Total Posts: 3567 |
|
|
| 15 Nov 2012 10:40 PM |
Can you explain a bit more on how to solve this. I don't have that much experience with scripting. |
|
|
| Report Abuse |
|
|
|
| 15 Nov 2012 10:43 PM |
sound2.Name = "Rsound"
Change to sound2.Name = "sound2" |
|
|
| Report Abuse |
|
|
BOZZSYLUX
|
  |
| Joined: 05 Sep 2009 |
| Total Posts: 3567 |
|
|
| 15 Nov 2012 10:46 PM |
I get the same error again.
Workspace.M102 105mm Cannon.Switch.FireGun:35: attempt to index global 'sound2' (a nil value) |
|
|
| Report Abuse |
|
|
BOZZSYLUX
|
  |
| Joined: 05 Sep 2009 |
| Total Posts: 3567 |
|
| |
|
BOZZSYLUX
|
  |
| Joined: 05 Sep 2009 |
| Total Posts: 3567 |
|
| |
|
|
| 17 Nov 2012 07:26 AM |
function fire(player) local sound = script.Parent:FindFirstChild("GunSound") if sound == nil then sound = Instance.new("Sound") sound.Name = "GunSound" sound.SoundId = "http://www.roblox.com/asset/?id=2101148" sound.Volume = 5 end sound2.Parent = script.Parent sound2 = Instance.new("Sound") sound2.Name = "Rsound" sound2.SoundId = "http://www.roblox.com/asset/?id=2697432" sound2.Volume = 5 sound2.Parent = script.Parent sound:play() wait(3) sound2:play() end
Try that.
-Want to learn to script? http://www.roblox.com/My/Groups.aspx?gid=730203 has all the information for you! |
|
|
| Report Abuse |
|
|
BOZZSYLUX
|
  |
| Joined: 05 Sep 2009 |
| Total Posts: 3567 |
|
|
| 17 Nov 2012 08:15 AM |
| That did not work for me as it said the same thing |
|
|
| Report Abuse |
|
|
thumper10
|
  |
| Joined: 17 Apr 2009 |
| Total Posts: 3304 |
|
|
| 17 Nov 2012 08:29 AM |
-- the problem is that you called it before you declared it function fire(player) local sound = script.Parent:FindFirstChild("GunSound") if sound == nil then sound = Instance.new("Sound") sound.Name = "GunSound" sound.SoundId = "http://www.roblox.com/asset/?id=2101148" sound.Volume = 5 sound2 = Instance.new("Sound") -- This was the problem sound2.Parent = script.Parent sound2.Name = "Rsound" sound2.SoundId = "http://www.roblox.com/asset/?id=2697432" sound2.Volume = 5 sound2.Parent = script.Parent end sound:play() wait(3) sound2:play() end
- thumper10, C# Lover |
|
|
| Report Abuse |
|
|
|
| 17 Nov 2012 08:46 AM |
BOZZ, I did not say the same thing.
-Want to learn to script? http://www.roblox.com/My/Groups.aspx?gid=730203 has all the information for you! |
|
|
| Report Abuse |
|
|
BOZZSYLUX
|
  |
| Joined: 05 Sep 2009 |
| Total Posts: 3567 |
|
|
| 17 Nov 2012 10:51 AM |
Hmm Thumper that might've did the trick but.. Now some other error popped up wich didn't pop out before. ( since it worked with 1 sound only) Output says;
Workspace.M102 105mm Cannon.Cannon.Switch.FireGun:83: 'eof' expected near 'end'
local spawnPos = barrel.CFrame * Vector3.new(6, 0, 0)
local dx = math.random(0,0) local dy = math.random(0,0) local dz = math.random(0,0) local mag = math.random(3000,3000)
local v = barrel.CFrame:vectorToWorldSpace(Vector3.new(mag + dx,dy,dz)) local missile = cannonBall:clone()
missile.Position = spawnPos missile.Velocity = v
local new_script = script.Parent.CannonBall:clone() new_script.Disabled = false new_script.Parent = missile
local creator_tag = Instance.new("ObjectValue") creator_tag.Value = player creator_tag.Name = "creator" creator_tag.Parent = missile
missile.Parent = game.Workspace
end <----- thats line 83.
|
|
|
| Report Abuse |
|
|
BOZZSYLUX
|
  |
| Joined: 05 Sep 2009 |
| Total Posts: 3567 |
|
| |
|
reflicted
|
  |
| Joined: 07 Nov 2012 |
| Total Posts: 265 |
|
|
| 17 Nov 2012 11:14 AM |
| The eof error means you have a loose end. Trace all of your functions and stuff and find the one that dosnt have a parent. |
|
|
| Report Abuse |
|
|
reflicted
|
  |
| Joined: 07 Nov 2012 |
| Total Posts: 265 |
|
|
| 17 Nov 2012 11:15 AM |
| Also put another end if thats not the error. :) |
|
|
| Report Abuse |
|
|
Raphael7
|
  |
| Joined: 03 Dec 2008 |
| Total Posts: 2479 |
|
|
| 17 Nov 2012 11:16 AM |
| If you had no functions or anything then an end doesn't matter and when it said sound2 was nil, you might've named sound2 to a different name or it just does not exist in where it's supposed to be. |
|
|
| Report Abuse |
|
|
BOZZSYLUX
|
  |
| Joined: 05 Sep 2009 |
| Total Posts: 3567 |
|
|
| 17 Nov 2012 11:41 AM |
Hmm so now I have removed the end wich resulted in hearing the firing sound again. But then again.. output says;
Workspace.M102 105mm Cannon.Cannon.Switch.FireGun:34: attempt to index global 'sound2' (a nil value)
I am kinda getting clueless now, is this my fault for my poor scripting or this roblox being a pain in the back?
|
|
|
| Report Abuse |
|
|
BOZZSYLUX
|
  |
| Joined: 05 Sep 2009 |
| Total Posts: 3567 |
|
|
| 17 Nov 2012 11:43 AM |
I am just gonna post the whole script, see if you guys could find any errors im kinda getting tired of solving this >.>
local switch = script.Parent local gunBarrelOne = script.Parent.Parent.GunBarrel.One
local debounce = false local gunOne = true
local cannonBall = Instance.new("Part") cannonBall.Size = Vector3.new(1,1,1) cannonBall.BrickColor = BrickColor.new("Really black") cannonBall.Shape = 0 cannonBall.BottomSurface = 0 cannonBall.TopSurface = 0 cannonBall.Name = "Cannon Shot" cannonBall.Elasticity = .1 cannonBall.Reflectance = 0 cannonBall.Friction = 0
function fire(player) local sound = script.Parent:FindFirstChild("GunSound") if sound == nil then sound = Instance.new("Sound") sound.Name = "GunSound" sound.SoundId = "http://www.roblox.com/asset?id=2101148" sound.Volume = 5 sound.Parent = script.Parent sound2 = Instance.new("Sound") sound2.Name = "Rsound" sound2.SoundId = "http://www.roblox.com/asset?id=2697432" sound2.Volume = 5 sound2.Parent = script.Parent end sound:play() wait(2) sound2:play() end
local missile = Instance.new("Part")
local barrel
if gunOne == true then barrel = gunBarrelOne gunOne = true end local spawnPos = barrel.CFrame * Vector3.new(6, 0, 0)
local dx = math.random(0,0) local dy = math.random(0,0) local dz = math.random(0,0) local mag = math.random(3000,3000)
local v = barrel.CFrame:vectorToWorldSpace(Vector3.new(mag + dx,dy,dz)) local missile = cannonBall:clone()
missile.Position = spawnPos missile.Velocity = v
local new_script = script.Parent.CannonBall:clone() new_script.Disabled = false new_script.Parent = missile
local creator_tag = Instance.new("ObjectValue") creator_tag.Value = player creator_tag.Name = "creator" creator_tag.Parent = missile
missile.Parent = game.Workspace
function onClicked() if debounce == false then debounce = true switch.BrickColor = BrickColor.new(21) fire(player) wait(5)
wait(0.5) debounce = false switch.BrickColor = BrickColor.new(37) end end
script.Parent.ClickDetector.MouseClick:connect(onClicked)
|
|
|
| Report Abuse |
|
|
BOZZSYLUX
|
  |
| Joined: 05 Sep 2009 |
| Total Posts: 3567 |
|
| |
|
|
| 18 Nov 2012 09:57 PM |
sound2 hasn't been set.
If you notice, there are no 'sound2 = Object' |
|
|
| Report Abuse |
|
|
BOZZSYLUX
|
  |
| Joined: 05 Sep 2009 |
| Total Posts: 3567 |
|
|
| 19 Nov 2012 06:30 AM |
| Nvm I have already fixed the problem, got help from Stravant ;3 |
|
|
| Report Abuse |
|
|