Thanks man that Function works awsome x-d , but i'm havin' some trouble with this code

.
Sync on
Sync rate 50
Hide mouse
x = screen width()/2
y = screen height()/2
GoSub Start
Start:
cls
Ink rgb(255,0,0),1
Box 0,0,screen width()-1,85
Box 554,86,screen width()-1,screen height()-1
Box 0,86,85,screen height()-1
Box 86,378,screen width()-1,screen height()-1
Ink rgb(255,255,255),1
Box 86,86,553,377
`-----------------
` Main Game Loop
`-----------------
Do
Ink rgb(0,0,200),1
Set cursor 130,50
Print "Press 's' to shake"
If upkey()=1 Then dec y
If downkey()=1 Then inc y
If leftkey()=1 Then dec x
If rightkey()=1 Then inc x
If keystate(31)=1
shakescreen(5,5,5,5)
GoSub Start
EndIf
If escapekey()=1 Then GoSub QuitGame
If x < 86 Then x = 86
If x > 553 Then x = 553
If y < 86 Then y = 86
If y > 377 Then y = 377
Ink rgb(0,0,0),1
Dot x,y
Sync
Wait 1
Loop
rem Function to make screen shake
Function shakescreen(xoff,yoff,velocity,time)
Get image 1,0,0,screen width(), screen height()
d = 1
For t = 1 To time
For x = 1 To xoff*d Step velocity*d
For y = 1 To yoff*d Step velocity*d
Sprite 1,x,y,1
SYNC
Next y
Next x
d = d * -1
Next t
EndFunction
QuitGame:
End
When 's' is pushed to go to the Function that shakes the screen and the program returns from the Function it goes to the Start Sub, then the sync rate seems to be different and the program just does'nt work like i want it.
Can someone tell me why this happens ¿
Thanks