Getting Function to repeat?

I’m trying to get a sort of anti-cheat working on pointshop for something im working on and I have the code down but the problem is the function isnt repeating itself after being called once. It works the first time but not after that. This is what I have so far.

Clientside:
[LUA]function PS:ToggleMenu()
if not PS.ShopMenu then --if the pointshop is closed then open it when shop_point is called
PS.ShopMenu = vgui.Create(‘DPointShopMenu’)
PS.ShopMenu:SetVisible(false)
net.Start( “AntiCheat” ) --send this message to the server when the pointshop is opened
net.SendToServer()
end

if PS.ShopMenu:IsVisible() then --if the shop is open then close it and remove the  anticheat timer
	PS.ShopMenu:Hide()
	gui.EnableScreenClicker(false)
	net.Start( "TimerDestroy" )
	net.SendToServer()
else
	PS.ShopMenu:Show()
	gui.EnableScreenClicker(true)
end

end

net.Receive( “CloseMenu”, function( length, ply
)LocalPlayer():ConCommand( “shop_point” ) --closes the shop menu and gives the expired session message.
LocalPlayer():PrintMessage( HUD_PRINTTALK, “Your POINTSHOP session has expired due to an anti-cheat measure.” )
end )[/LUA]

Serverside:
[LUA]net.Receive( “AntiCheat”, function(len, ply)
timer.Create(“point”, 10, 1, function()
if !IsValid(ply) then return end --receive the message and create the anticheat timer and send the message back.
net.Start( “CloseMenu” )
net.Send( ply )
end)
end )

net.Receive( “TimerDestroy”, function(len, ply) --destroys the anticheat timer.
timer.Destroy( “point” )
end )
[/LUA]

I commented most lines so you can see my thought process. The problem isnt that the code doesnt work, because it does, but that the code only runs when run right when the server starts. After that, it doesnt work again and I have to restart the server. Any help would be greatly appreciated.

Change the 1 to a 0 and it will repeat indefinitely. You are telling it to only run once.

I just want to point out you are creating a timer called “point” when a net message is received from a player. So what happens when another player sends the net message? It will re-create the timer with the same name (“point”) and wipe out the old one, so your timer is only ever going to be affecting 1 player.

Thanks a lot! What can i do to fix that problem?

Name the timer something that is relevant to the player you are receiving the message from. i.e. “point”…ply:Name().

Ah, well it kinda works now like it should. It runs on a 30 second loop it seems so if you open the menu at 28 seconds it will close in 2 seconds with the message but i guess i can work with it. Thanks guys.

EDIT:
After some more testing it seems that with both of your fixes, after you open the menu once, the concommand is triggered after every 30 seconds now so it keeps opening and closing the menu every 30 seconds and spamming the message with it, so its not fixed after all. Any more ideas?

-bump- any help please?

When you close the menu, do timer.Remove(timername)

Thats what I did in the code but now that I think about it, wouldnt that just lead me back to the original problem of the function only running when the server starts and not again after that? i dont know what else to do.

EDIT:
Yes, after doing some more testing with your method bob it removes the timer and the function doesnt work again.

Make sure it creates a new timer when you open it.

I figured out the problem with it. Turns out everything we were doing was right, but the net message was being sent in the wrong place. The timer was started when the vgui menu was created, like it was supposed to, but the vgui menu is never removed when you closed it, only hidden. So because the vgui.Create was never called again (it was PS.ShopMenu:Show() instead) the timer wasnt called again. I fixed this by making a timer for when PS.ShopMenu:Show() was called also. Thanks for all the help everyone.

[LUA]function PS:ToggleMenu()
if not PS.ShopMenu then
PS.ShopMenu = vgui.Create(‘DPointShopMenu’)
PS.ShopMenu:SetVisible(false)
net.Start( “Lock” )
net.SendToServer()
end

if PS.ShopMenu:IsVisible() then
	PS.ShopMenu:Hide()
	gui.EnableScreenClicker(false)
else
	PS.ShopMenu:Show()
	gui.EnableScreenClicker(true)
	net.Start( "Lock" )
	net.SendToServer()
end

end[/LUA]