• Experience Fuction SWEP error
    8 replies, posted
Hey We have a star wars RP server and we have a lightsaber force power that gives experience but soon as more then one person starts meditating it stops giving exp [CODE]if self.Owner:KeyPressed(IN_ATTACK2) then local level = tonumber( self.Owner:GetNWInt("level")) timer.Create( "setforceTimer", 0.3, 0, function() if self:GetForce() < ( MaxForce + level ) then self:SetForce( self:GetForce() + 1 ) else return end end) timer.Create( "healTimer", 1, 0, function() heal(self) end) timer.Create( "expTimer", 1, 0, function() self.Owner:GiveExp(0.25) end)[/CODE]
Set the timer.Create name to something unique with SteamID.
[QUOTE=code_gs;51399164]Set the timer.Create name to something unique with SteamID.[/QUOTE] How would one do that? I am new to this lua coding.
Change setforceTimer to "setforceTimer" .. ply:SteamID(). This concatenates the timer name with the player's SteamID.
[QUOTE=code_gs;51399245]Change setforceTimer to "setforceTimer" .. ply:SteamID(). This concatenates the timer name with the player's SteamID.[/QUOTE] Just tried, doesn't work. [editline]20th November 2016[/editline] [code]timer.Create( "setforceTimer" .. ply:SteamID(), 0.3, 0, function() if self:GetForce() < ( MaxForce + level ) then self:SetForce( self:GetForce() + 1 ) else return end end)[/code]
You have to do that with every timer.
[QUOTE=code_gs;51399261]You have to do that with every timer.[/QUOTE] If you mean like that, [code] timer.Create( "setforceTimer" .. ply:SteamID(), 0.3, 0, function() if self:GetForce() < ( MaxForce + level ) then self:SetForce( self:GetForce() + 1 ) else return end end) timer.Create( "healTimer" .. ply:SteamID(), 1, 0, function() heal(self) end) timer.Create( "expTimer" .. ply:SteamID(), 1, 0, function() self.Owner:GiveExp(0.25) end) [/code] Its not working [editline]20th November 2016[/editline] The error produced when I try is [code] [ERROR] addons/star wars lightsabers/lua/weapons/weapon_lightsaber.lua:511: attempt to index global 'ply' (a nil value) 1. think - addons/star wars lightsabers/lua/weapons/weapon_lightsaber.lua:511 2. unknown - addons/star wars lightsabers/lua/weapons/weapon_lightsaber.lua:1442 [/code]
Change ply to self.Owner
[QUOTE=code_gs;51399300]Change ply to self.Owner[/QUOTE] That worked, thank you.
Sorry, you need to Log In to post a reply to this thread.