My garrysmod crashes from this code..

I have no clue why this is happening…
When I have this code in my gamemode, it crashes.

Ps, I don’t need any critisism about my coding, I havent been coding for long.

This is in init.lua

[lua]
function GM:Think()

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

local AimE = v:GetEyeTraceNoCursor().Entity
local trace = v:GetEyeTrace()

if v:Health()>100 then
v:SetHealth( 100 )
end

if v:GetMoney()<0 then
v:SetMoney( 0 )
v:SaveMoney()
file.Write(gmod.GetGamemode().Name …"/Money/"… string.gsub(v:SteamID(), “:”, “_”) …".txt", tostring(v:GetMoney()) )
end

if AimE:IsNPC() and v:KeyDown(32) and AimE:GetClass()==“npc_citizen” then
if trace.HitPos:Distance(v:GetShootPos()) <= 75 then
v:ConCommand(“QuestNPC1”)
end
end

if v:KeyDown(32) and AimE:GetClass()==“prop_ragdoll” and v:GetQuest1()==4 then
if trace.HitPos:Distance(v:GetShootPos()) <= 75 then
v:SetQuest1(5)
v:SaveQuest1()
v:PrintMessage( HUD_PRINTTALK, “You found Henrich… You better report back to Jonas.” )
file.Write(gmod.GetGamemode().Name …"/Quest/"… string.gsub(v:SteamID(), “:”, “_”) …".txt", tostring(v:GetQuest1()) )
end
end

if v:KeyDown(32) and AimE:GetModel()==“models/props_c17/gravestone_coffinpiece002a.mdl” and v:GetQuest1()==7 then
if trace.HitPos:Distance(v:GetShootPos()) <= 75 then
v:SetQuest1(8)
v:SaveQuest1()
v:PrintMessage( HUD_PRINTTALK, “You search Henrich grave…
You found a letter.
The letter reads: X=-3600, Y=-4325” )
file.Write(gmod.GetGamemode().Name …"/Quest/"… string.gsub(v:SteamID(), “:”, “_”) …".txt", tostring(v:GetQuest1()) )
end
end

if v:KeyDown(32) and AimE:GetModel()==“models/props_wasteland/rockcliff_cluster03a.mdl” and v:GetQuest1()==8 then
if trace.HitPos:Distance(v:GetShootPos()) <= 75 then
v:SetQuest1(9)
v:SaveQuest1()
v:PrintMessage( HUD_PRINTTALK, “You search the rock…
" )
file.Write(gmod.GetGamemode().Name …”/Quest/"… string.gsub(v:SteamID(), “:”, “_”) …".txt", tostring(v:GetQuest1()) )
end
end

end
end
[/lua]

http://dl.dropbox.com/u/3684498/Dammit.png

Well gosh, I’d say it’s probably because you’re doing several file.Writes every frame. That generally slows down your computer.

Well, its only called when I do the shit. It does not write otherwise.

its hooked to think…it calls it alot…

Either way, that’s a ridiculously awful way of saving data. You should A. be using sql tables or using GLON, and B. should only be saving when things change, not every frame.

Also, indent that code!

Why are you using numbers instead of IN_ enumerations in KeyDown?
It’s very unlikely, but if the enumerations change, then you will not be passing the IN_ key that you think you are. Also it becomes an awful lot easier to read.

You should hook this to KeyPress, so it’s not executed every frame.

Thanks for the tips, This happend because I started the gamemode when I had even less experience with lua.