I guess i need a little help.

Well, so I’m doing this gamemode for fun, because I’m starting to learn lua, but I’m getting this weird problem that i cannot fix. What it’s doing is when the round ends it respawns all players. It does work, but i get this error:

[lua]
[ERROR] gamemodes/pdm/gamemode/shared.lua:41: attempt to call global ‘roundend’ (a nil value)

  1. End - gamemodes/pdm/gamemode/shared.lua:41
  2. unknown - gamemodes/pdm/gamemode/shared.lua:59

[/lua]

Shared.lua file:
[lua]function GM:Initialize()
team.SetUp(1, “Faggot”, Color( 0,0,255,255))
team.SetUp(2, “Russian”, Color( 0,255,0,255))

end

round = {}

round.Break = 5
round.Time = 5

round.TimeLeft = -1
round.Breaking = false

function round.Broadcast(Text)
for k, v in pairs(player.GetAll()) do
v:ConCommand(“play buttons/button17.wav”)
v:ChatPrint(Text)

end

end

function round.Begin()

round.Broadcast("Round starting! Round ends in " .. round.Time .. " seconds!")
round.TimeLeft = round.Time

end

function round.End()

roundend()
round.Broadcast("Round over! Next round in " .. round.Break .. " seconds!")
round.TimeLeft = round.Break

end

function round.Handle()
if (round.TimeLeft == -1) then
round.Begin()
return
end

round.TimeLeft = round.TimeLeft - 1

if (round.TimeLeft == 0) then
	if (round.Breaking) then
		round.Begin()
		round.Breaking = false
	else
		round.End()
		round.Breaking = true
	end
end

end
timer.Create(“round.Handle”, 1, 0, round.Handle)
[/lua]

init.lua file:

[lua]AddCSLuaFile( “cl_init.lua” )
AddCSLuaFile( “shared.lua” )

include( “shared.lua” )

function GM:PlayerInitialSpawn( ply )

ply:SetTeam( 1 ) 

end

function GM:PlayerLoadout(ply)

ply:StripWeapons() 

if ply:Team() == 1 then 
	ply:Give("weapon_physcannon") 

else if ply:Team() == 2 then 
	ply:Give("weapon_physgun") 

end
end
end

function roundend()
for k, v in pairs(player.GetAll()) do

	v:Spawn()

end

end

function team_1( ply )
ply:Spawn()
ply:SetTeam( 1 )
ply:ChatPrint(“Your loadout will change the next time you respawn.”)

end

function team_2( ply )
ply:Spawn()
ply:SetTeam( 2 )
ply:ChatPrint(“Your loadout will change the next time you respawn.”)
end

concommand.Add( “team_1”, team_1 )
concommand.Add( “team_2”, team_2 )

function GM:ShowHelp(ply)
umsg.Start(“MyMenu”, ply)
umsg.End()
end

[/lua]

I hope that someone can help me.

Use [lua] tags instead.
Okay, I got the fix (probably).

change line
[lua]round = {}[/lua]
to
[lua]round = round or {}[/lua]

Because you might be reloading the script while it runs so round table resets and then the old timer is trying to run a function that no longer exists BECAUSE round tbl is empty.

Did not seem to fix it, sadly.

Alright, we’ll look for other solution.
Just change

[quote]
tags to [lua] so we get a proper highlighting and numeration.

@Edit:
Nvm. I pasted it into my editor.
You are trying to run a function that doesn’t exist: roundend()

@Edit2:
Now I see it in init.lua.
Please, add the blasted highlighting because I can’t focus when the digits blend so much lol.

Done, thanks a bunch for helping me.

Edit? Hmm? It does exist. It’s in the init.lua file. The function works. It just gives me that error.

My guess is that roundend() is a server function and you’re trying to call it clientside in the shared file.

Uh… ninja’d
Didn’t spot it on time.

No, it still gives me that error :stuck_out_tongue:

No, i changed those quote to lua. That’s why i said done :stuck_out_tongue:

Edit: So what do i need to change?

And to think 3 months ago I was asking you to add me some custom printers for my shitty darkrp server :suicide:

Arcaneex is right.
If you want to fix it just change:
[lua]roundend()[/lua]
to
[lua]if SERVER then
roundend()
end
[/lua]

Also, if I might add… your scripting is very clumsy, I just noticed that you are running 99% of your code on both sides and I assume you are testing it on singleplayer, otherwise it would pop way more than just 1 error.
You should learn about differences between serverside, clientside and shared and make sure you are only executing functions in their proper realms and if you really want to do the opposite then use networking.

Thank you, both. You’ve been a great help.

Yeah. Everything changes when you don’t script regulary :stuck_out_tongue: