Widths
|
  |
| Joined: 12 Aug 2014 |
| Total Posts: 41286 |
|
|
| 09 Aug 2016 02:37 PM |
My following script doesn't run anything past the 4 initial prints, when it should be printing lots of other things. I can't seem to find the problem anywhere
math.randomseed(tick()%16) local grass = {} local cave = {} local beach = {} local water = {} wait(.01) for i,v in pairs(_G.Pokemon) do for i=1,v.SpawnRate do if v.Biome == "Grass" then table.insert(grass, v.Name) elseif v.Biome == "Cave" then table.insert(cave, v.Name) elseif v.Biome == "Beach" then table.insert(beach, v.Name) elseif v.Biome == "Water" then table.insert(water, v.Name) end end end print("Grass: "..#grass) print("Cave: "..#cave) print("Beach: "..#beach) print("Water: "..#water) game.Players.PlayerAdded:connect(function(plr) plr.CharacterAdded(function(chr) print(chr.Name) spawn(function() local running = false chr.Humanoid.Running:connect(function(s) if s>0 then running = true else running = false end end) local last_Pokemon = tick() while wait(.1) do print(running) local leg = chr:FindFirstChild("Left Leg") local ray = Ray.new(leg.Position, Vector3.new(0,-10,0)) local hit, position = workspace:FindPartOnRay(ray, chr) if hit ~= nil and running then local color = tostring(hit.BrickColor) local colors = { ["Shamrock"] = "Grass", ["Pine Cone"] = "Cave", ["Bright bluish green"] = "Water", ["Cashmere"] = "Beach" } local Type = colors[color] if Type ~= nil then print(Type) local chance = 100 local rand = math.random(1,chance) if rand == math.ceil(chance/2) and (tick() - last_Pokemon >= 20) then print("Pokemon?") last_Pokemon = tick() local spawns if Type == "Water" then spawns = water elseif Type == "Grass" then spawns = grass elseif Type == "Cave" then spawns = cave elseif Type == "Beach" then spawns = beach end local Rand = spawns[math.random(1, #spawns)] print(#spawns) if Rand ~= nil then print(Rand) else print("No pokemon in this biome :( "..Type) end end else print(color) end end end end) end) end)
-iJava |
|
|
| Report Abuse |
|
|
Soybeen
|
  |
| Joined: 17 Feb 2010 |
| Total Posts: 21462 |
|
|
| 09 Aug 2016 02:42 PM |
plr.CharacterAdded(function(chr) should be plr.CharacterAdded:connect(function(chr)
|
|
|
| Report Abuse |
|
|
|
| 09 Aug 2016 02:42 PM |
try it live
This siggy is copyrighted © |
|
|
| Report Abuse |
|
|
|
| 09 Aug 2016 02:42 PM |
| I would recommend putting the PlayerAdded handler at the top. That way it's sure to run. If you try running the test server with 1 player, wait and then run it with a second, the second one should work. If that happens, then this is your problem. |
|
|
| Report Abuse |
|
|
Soybeen
|
  |
| Joined: 17 Feb 2010 |
| Total Posts: 21462 |
|
| |
|
Widths
|
  |
| Joined: 12 Aug 2014 |
| Total Posts: 41286 |
|
|
| 09 Aug 2016 02:44 PM |
I just pasted it wrong, I'm using that @Soybeen
-iJava |
|
|
| Report Abuse |
|
|
Soybeen
|
  |
| Joined: 17 Feb 2010 |
| Total Posts: 21462 |
|
|
| 09 Aug 2016 02:44 PM |
Where is this code running?
|
|
|
| Report Abuse |
|
|
Widths
|
  |
| Joined: 12 Aug 2014 |
| Total Posts: 41286 |
|
|
| 09 Aug 2016 02:47 PM |
workspace, under a ServerScript
-iJava |
|
|
| Report Abuse |
|
|
Soybeen
|
  |
| Joined: 17 Feb 2010 |
| Total Posts: 21462 |
|
|
| 09 Aug 2016 02:54 PM |
spawn(f) executes function f after thread next yields. I think you should try a coroutine instead(?)
Not sure if this is the problem.
|
|
|
| Report Abuse |
|
|
Widths
|
  |
| Joined: 12 Aug 2014 |
| Total Posts: 41286 |
|
|
| 09 Aug 2016 02:54 PM |
I switched so spawn from coroutine thinking that was the issue, but it changed nothing. The print above the coroutine never prints either
-iJava |
|
|
| Report Abuse |
|
|
Soybeen
|
  |
| Joined: 17 Feb 2010 |
| Total Posts: 21462 |
|
| |
|
DevVince
|
  |
| Joined: 08 Nov 2008 |
| Total Posts: 9245 |
|
|
| 09 Aug 2016 03:07 PM |
~~Magic~~ ????????
math.randomseed(tick())--Shortening the number will only make it not as random, leave it at tick(). grass = {} cave = {} beach = {} water = {} types = {{'Grass', grass},{'Cave', cave},{'Beach', beach},{'Water', water}} chance = 100 colors = { ['Shamrock'] = 'Grass', ['Pine Cone'] = 'Cave', ['Bright bluish green'] = 'Water', ['Cashmere'] = 'Beach' }
function sort(input) for i,v in pairs(types) do if v[1] == input then return v[2] end end end
for i,v in pairs(_G.Pokemon) do for i=1,v.SpawnRate do table.insert(sort(v.Biome), v.Biome) end end
print('Grass: ', #grass, ' Cave: ', #cave, ' Beach: ', #beach, ' Water: ', #water)
game.Players.PlayerAdded:connect(function(p) p.CharacterAdded(function(c) local h = c:WaitForChild'Humanoid' local leg = c:WaitForChild'HumanoidRootPart' local last_Pokemon = tick() local running = false local lv = 0 function CheckForPokemon(cv) while wait(0.1) do if cv < lv or not running then break end local ray = Ray.new(leg.Position, Vector3.new(0,-10,0)) local hit, position = workspace:FindPartOnRay(ray, c) if hit and running then local color = tostring(hit.BrickColor) local Type = colors[color] if Type then local rand = math.random(0, chance) if rand == math.ceil(chance/2) and (tick() - last_Pokemon >= 20) then last_Pokemon = tick() local spawns = sort(Type) local Rand = spawns[math.random(1, #spawns)] if Rand then print(Rand) end end end end end end h.Running:connect(function(s) if s > 0 then running = true lv = lv + 1 CheckForPokemon(lv) else running = false end end) end) end) |
|
|
| Report Abuse |
|
|
Widths
|
  |
| Joined: 12 Aug 2014 |
| Total Posts: 41286 |
|
|
| 09 Aug 2016 03:09 PM |
@Dev Thanks, looks a lot cleaner, but I get this error now:
15:09:11.312 - Workspace.WildPokemon:23: bad argument #1 to 'pairs' (table expected, got nil) 15:09:11.313 - Stack Begin 15:09:11.313 - Script 'Workspace.WildPokemon', Line 23
-iJava |
|
|
| Report Abuse |
|
|
DevVince
|
  |
| Joined: 08 Nov 2008 |
| Total Posts: 9245 |
|
|
| 09 Aug 2016 03:10 PM |
Line 32 to: p.CharacterAdded:connect(function(c) |
|
|
| Report Abuse |
|
|
DevVince
|
  |
| Joined: 08 Nov 2008 |
| Total Posts: 9245 |
|
|
| 09 Aug 2016 03:11 PM |
Line 23 is your problem it's your hidden array. aka: _G.Pokemon |
|
|
| Report Abuse |
|
|
Widths
|
  |
| Joined: 12 Aug 2014 |
| Total Posts: 41286 |
|
|
| 09 Aug 2016 03:12 PM |
I see, thanks. Adding a wait above that should fix it (I define _G.Pokemon in a different script, so there's a slight delay)
-iJava |
|
|
| Report Abuse |
|
|
DevVince
|
  |
| Joined: 08 Nov 2008 |
| Total Posts: 9245 |
|
|
| 09 Aug 2016 03:13 PM |
| Also made it so it isn't loop all the time because that's just dumb, so now the server won't need as much resources for each player. :) |
|
|
| Report Abuse |
|
|
DevVince
|
  |
| Joined: 08 Nov 2008 |
| Total Posts: 9245 |
|
|
| 09 Aug 2016 03:14 PM |
| Why are you even using global functions? Module scripts> |
|
|
| Report Abuse |
|
|
Widths
|
  |
| Joined: 12 Aug 2014 |
| Total Posts: 41286 |
|
|
| 09 Aug 2016 03:15 PM |
Thanks! However, for some reason it still isn't working. It prints the first print as it did in the original, but adding this after CharacterAdded and there's nothing printed: print("Test")
could it just be that I'm in studio? My script was working fine with CharacterAdded in studio an hour ago, and my other scripts using it work fine as well
-iJava |
|
|
| Report Abuse |
|
|
DevVince
|
  |
| Joined: 08 Nov 2008 |
| Total Posts: 9245 |
|
|
| 09 Aug 2016 03:16 PM |
| Pokemon = require(script:WaitForChild'MassivePokemonArray')--Module scripts are better to use then global functions. |
|
|
| Report Abuse |
|
|
DevVince
|
  |
| Joined: 08 Nov 2008 |
| Total Posts: 9245 |
|
| |
|
Widths
|
  |
| Joined: 12 Aug 2014 |
| Total Posts: 41286 |
|
|
| 09 Aug 2016 03:19 PM |
Line 32 is p.CharacterAdded for me
there's no errors anymore, I added a wait(.01) under math.randomseed
-iJava |
|
|
| Report Abuse |
|
|
DevVince
|
  |
| Joined: 08 Nov 2008 |
| Total Posts: 9245 |
|
|
| 09 Aug 2016 03:21 PM |
You should really switch over to module scripts instead of global functions.
Anyways this should be line 32: p.CharacterAdded:connect(function(c) Not: p.CharacterAdded |
|
|
| Report Abuse |
|
|
Widths
|
  |
| Joined: 12 Aug 2014 |
| Total Posts: 41286 |
|
|
| 09 Aug 2016 03:22 PM |
Oh, yeah I fixed that part already
I might switch to a module script later, I've just never used one before
-iJava |
|
|
| Report Abuse |
|
|
Widths
|
  |
| Joined: 12 Aug 2014 |
| Total Posts: 41286 |
|
|
| 09 Aug 2016 03:28 PM |
Still, nothing is printing This is what I'm using currently:
math.randomseed(tick())--Shortening the number will only make it not as random, leave it at tick(). grass = {} cave = {} beach = {} water = {} types = {{'Grass', grass},{'Cave', cave},{'Beach', beach},{'Water', water}} chance = 10 colors = { ['Shamrock'] = 'Grass', ['Pine Cone'] = 'Cave', ['Bright bluish green'] = 'Water', ['Cashmere'] = 'Beach' }
function sort(input) for i,v in pairs(types) do if v[1] == input then return v[2] end end end wait(.01) for i,v in pairs(_G.Pokemon) do for i=1,v.SpawnRate do table.insert(sort(v.Biome), v.Biome) end end
print('Grass: ', #grass, ' Cave: ', #cave, ' Beach: ', #beach, ' Water: ', #water)
game.Players.PlayerAdded:connect(function(p) p.CharacterAdded:connect(function(c) print("Test") local h = c:WaitForChild('Humanoid') local leg = c:WaitForChild('HumanoidRootPart') local last_Pokemon = tick() local running = false local lv = 0 function CheckForPokemon(cv) while wait(0.1) do if cv < lv or not running then break end local ray = Ray.new(leg.Position, Vector3.new(0,-10,0)) local hit, position = workspace:FindPartOnRay(ray, c) if hit and running then local color = tostring(hit.BrickColor) local Type = colors[color] if Type then local rand = math.random(0, chance) if rand == math.ceil(chance/2) and (tick() - last_Pokemon >= 2) then last_Pokemon = tick() local spawns = sort(Type) local Rand = spawns[math.random(1, #spawns)] if Rand then print(Rand) else print("Nope") end end end end end end h.Running:connect(function(s) if s > 0 then running = true lv = lv + 1 CheckForPokemon(lv) else running = false end end) end) end)
-iJava |
|
|
| Report Abuse |
|
|